CharacterSetFilter

package com.ofrick;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterSetFilter implements Filter {

@Override
public void destroy() {}

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
// Respect the client-specified character encoding
// (see HTTP specification section 3.4.1)
if (null == servletRequest.getCharacterEncoding()) {
servletRequest.setCharacterEncoding(„UTF-8“);
}
chain.doFilter(servletRequest, servletResponse);
System.out.println(„response committed? “ + servletResponse.isCommitted());
System.out.println(String.format(„response character-set: %s“, servletResponse.getCharacterEncoding()));
// servletResponse.setCharacterEncoding(„UTF-8“);
}

@Override
public void init(FilterConfig filterConfig) throws ServletException {}

}

Veröffentlicht unter Allgemein

read UTF-8 csv file with Perl

use warnings;
use strict;

my $filename = $ARGV[0] or die "Need to get CSV file on the command line\n";
my $outfile = $ARGV[1] or die "Need to get CSV file on the command line\n";

open(FH, '<:encoding(utf8)', $filename) or die $!;
open(FHOUT, '>:encoding(UTF-8)', $outfile) or die $!;

my $char;
my $read;
my $infield = 0;
my $column = 0;
my $row = 0;
my $value = "";

while($read = read FH, $char, 1){
  if ( $char eq "'" && $infield == 0 ) {
    # field begin
    $infield = 1;
    $column++;
  } elsif ( $char eq "'" && $infield == 1 ) {
    # field end
    $infield = 0;
    print "(".$value.")";
    print FHOUT $value;
    $value = "";
  } elsif ( $char eq "\n" && $infield == 0 ) {
    # end of record
    $column = 0;
    $row++;
    print FHOUT "\n";
  } elsif ( $char eq "," && $infield == 0 ) {
    # comma while not in field = separator of col
    print FHOUT "\t";
  } else {
    # its a value
    $value = $value . $char;
  }
 #   my @fields = split "," , $_;
 #  ( $fields[0] && print $fields[0] ) || print "";
}

close(FHOUT);
close(FH);
Veröffentlicht unter Allgemein

download data from localStorage

var json = localStorage.getItem('theData');
var blob = new Blob([json], {type: "application/json"});
var url = URL.createObjectURL(blob);

var a = document.createElement('a');
a.download = "backup.json";
a.href = url;
a.textContent = "Download backup.json";

($ == undefined ) ? document.body.appendChild(a) : $("body").append(a);
Veröffentlicht unter Allgemein

httpd with PHP and sqlite3 with SELinux

mkdir /var/www/data

semanage fcontext -a -t httpd_sys_rw_content_t „/var/www/data(/.*)?“

restorecon -Rv /var/www

chown -R apache:apache data

 

<?php

$dbhandle = new SQLite3(‚/var/www/data/mysqlitedb.db‘);
$sql = „CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY  AUTOINCREMENT, bar STRING)“;
$result = $dbhandle->query($sql);

Veröffentlicht unter Allgemein

Jasperreports with Maven in Eclipse

  1. pom.xml
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>com.ofrick</groupId>
    
    <artifactId>jasper</artifactId>
    
    <version>0.0.1-SNAPSHOT</version>
    
    <dependencies>
    
    <!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports -->
    
    <dependency>
    
    <groupId>net.sf.jasperreports</groupId>
    
    <artifactId>jasperreports</artifactId>
    
    <version>6.15.0</version>
    
    </dependency>
    
    </dependencies>
    
    </project>

2. Fix error for com.lowagie itext 2.1.7.js8

Download jar from http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js8/itext-2.1.7.js8.jar

In Eclipse, Run Maven Build…  Goal install:install-file
in JRE Tab under VM arguments:
-DgroupId=com.lowagie -DartifactId=itext -Dversion=2.1.7.js8 -Dfile=C:\Users\O\Downloads\itext-2.1.7.js8.jar -DgeneratePom=true -Dpackaging=jar

3. Do Maven Update Project

Veröffentlicht unter Allgemein

install a jar locally for maven

\apache-maven-3.6.3\bin\mvn install:install-file -DgroupId=com.ofrick.libs -DartifactId=ojdbc6 -Dversion=11.2.0.4.0 -Dfile=C:\Temp\ojdbc6-11.2.0.4.0.jar -DgeneratePom=true -Dpackaging=jar

Veröffentlicht unter Allgemein

package.jdo

if id is not needed as a number in the application

<class name=“Author“ table=“MERIT_AUTHOR“>
<datastore-identity strategy=“sequence“ sequence=“AUTHOR_ID_SEQ“ column=“AUTHOR_ID“/>
<field name=“firstName“>
<column name=“FIRSTNAME“/>
</field>
<field name=“lastName“>
<column name=“LASTNAME“/>
</field>
<field name=“userName“>
<column name=“USERNAME“/>
</field>
<field name=“posts“ mapped-by=“author“>
<collection element-type=“entity.Post“/>
</field>
</class>

 

to use the id

<sequence name=“WEBSESSION_ID_SEQ“ datastore-sequence=“MERIT_WEBSESSION_SEQ“ strategy=“noncontiguous“ allocation-size=“1″ initial-value=“1″/>
<class name=“WebSession“>
<field name=“id“ primary-key=“true“ value-strategy=“sequence“ sequence=“WEBSESSION_ID_SEQ“/>
</class>

 

Veröffentlicht unter Allgemein

Oracle XE

Development Environment:

Install Oracle XE

on CentOS, check tmpfs in /etc/fstab

none    /dev/shm    tmpfs    defaults,size=2G      0 0

df -h /dev/shm

 

CONNECT AS SYSDBA

Username: SYSTEM

SELECT
username,
default_tablespace,
profile,
authentication_type
FROM
dba_users
WHERE
account_status = ‚OPEN‘;

SELECT TABLESPACE_NAME, STATUS, CONTENTS FROM USER_TABLESPACES;

CREATE USER john IDENTIFIED BY passwordhere DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS;

GRANT CREATE SESSION TO john;

GRANT CREATE TABLE, CREATE VIEW, CREATE PROCEDURE, CREATE SEQUENCE TO john

Veröffentlicht unter Allgemein

SystemCommand cfm

 

 <cftry>
// use java utility SystemCommand which kills task properly after timeout
// and throw an Exception then
<cfset cmd = createObject("java","au.com.webcode.util.SystemCommand").init()>
<cfset command = "cmd.exe /C #mkvdk_exe_script# >> #resultLog# 2>&1">
<cfset envp = arraynew(1)>
<cfset timeoutAsAString = "3600000">
<cfset cwd = "F:\logfile\application\searchlog\mkvdk\doc\">
<cfset result = cmd.execute(command, envp, timeoutAsAString, cwd)>
<cfcatch>
<!--- ignore timeout and continue, to allow index the next batch --->
</cfcatch>
</cftry>

 

Veröffentlicht unter Allgemein