Skip to content

Instantly share code, notes, and snippets.

View vladaman's full-sized avatar

Vladimir Vlach vladaman

View GitHub Profile
@vladaman
vladaman / gist:5785306
Created June 14, 2013 21:11
Encrypt/Decrypt using AES. The key must be 128bits
private static String encrypt(String key, String data) throws Exception {
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] res = cipher.doFinal(data.getBytes());
return Hex.encodeHexString(res);
}
private static String decrypt(String key, String d) throws Exception {
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
@vladaman
vladaman / gist:5799970
Last active December 18, 2015 14:49
Parses generated Java classes with Thrift Objects and adds @JsonIgnore to fields which are not supposed to be saved in Database (MongoDB)
import re
import os
regex = 'public void set.*IsSet|public boolean isSet.*|public int get.*Size|public java.util.Iterator'
for filename in os.listdir("."):
if filename.endswith(".java"):
os.rename(filename, filename + ".bak")
f = open(filename + ".bak", 'r')
@vladaman
vladaman / sendMSMQ.vbs
Created August 29, 2013 09:02
Sends and Receives messages using MSMQ in vb script
Option Explicit
const MQ_SEND_ACCESS = 2
const MQ_DENY_NONE = 0
const MQ_RECEIVE_ACCESS = 1
const MQ_NO_TRANSACTION = 0
const MQ_MTS_TRANSACTION = 1
const MQ_SINGLE_MESSAGE = 3
Dim objArgs
@vladaman
vladaman / exportMSSQLTables.sql
Created August 29, 2013 11:32
Export all tables into individual files
/* MS SQL Commands */
exec sp_configure 'show advanced options', 1
RECONFIGURE
exec sp_configure 'xp_cmdshell', 1
RECONFIGURE
exec sp_MSforeachtable 'master..xp_cmdshell ''bcp "SELECT * FROM DBName.?" queryout "Z:\?.txt" -S localhost -T -c -q'''
@vladaman
vladaman / SCIDReader.java
Last active February 10, 2024 21:54
Sierra Chart SCID Format Reader in Java
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.sql.Date;
import java.util.Calendar;
public class SCIDReader {
@vladaman
vladaman / amazon-kinesis.php
Created April 8, 2014 17:28
PHP Code to request Temporary Amazon AMI Credentials and publish message dummy message to Kinesis Service
<?php
require 'aws-autoloader.php';
use Aws\Sts\StsClient;
use Aws\Kinesis\KinesisClient;
// In real applications, the following code is part of your trusted code.
// It has your security credentials that you use to obtain temporary
// security credentials.
$sts = StsClient::factory(array(
'key' => 'ACCESS-KEY-HERE',
@vladaman
vladaman / amazon-kinesis-merge.php
Created April 8, 2014 18:57
PHP Script to split and merge Amazon Kinesis Streams
<?php
require 'aws-autoloader.php';
use Aws\Kinesis\KinesisClient;
// In real applications, the following code is part of your trusted code.
// It has your security credentials that you use to obtain temporary
// security credentials.
// Resource Policy to limit access to just some streams
/*
@vladaman
vladaman / CZ-psc-okresy.cypher
Last active August 30, 2015 20:47
Databáze všech PSČ - Příkazy k vytvoření Neo4j databaze poštovních směrovacích čísel, včetne jejich GPS souřadnich, relaci a nadrazenych okresu a vazeb mezi nimi (sousedni okresy)
begin
create (_2:`GeoZipCode` {`businesses_count`:0, `citizens_count`:0, `country_code`:"CZ", `guid`:329527073160, `lat`:50.403267, `lng`:12.769570, `post_name`:"Abertamy", `zip_code`:"36235"})
create (_3:`GeoOkres` {`guid`:292887945539, `lat`:0.000000, `lng`:0.000000, `okres_code`:"3403", `okres_name`:"Karlovy Vary"})
create (_4:`GeoZipCode` {`businesses_count`:0, `citizens_count`:0, `country_code`:"CZ", `guid`:93811663291, `lat`:50.500179, `lng`:16.020939, `post_name`:"Úpice", `zip_code`:"54232"})
create (_5:`GeoOkres` {`guid`:164828119722, `lat`:0.000000, `lng`:0.000000, `okres_code`:"3610", `okres_name`:"Trutnov"})
create (_6:`GeoZipCode` {`businesses_count`:0, `citizens_count`:0, `country_code`:"CZ", `guid`:236641299731, `lat`:49.295494, `lng`:16.658679, `post_name`:"Adamov 1", `zip_code`:"67904"})
create (_7:`GeoOkres` {`guid`:80042635560, `lat`:0.000000, `lng`:0.000000, `okres_code`:"3701", `okres_name`:"Blansko"})
create (_8:`GeoZipCode` {`businesses_count`:0, `citizens_count`:0, `country_code`:"CZ",
@vladaman
vladaman / bq-geohash-udf.sql
Last active July 2, 2021 02:59
Google BigQuery standardSQL UDF function to decode geohash string into bounding box and coordinates
#standardSQL
CREATE TEMPORARY FUNCTION geohashDecode(geohash STRING)
RETURNS STRUCT<bbox ARRAY<FLOAT64>, lat FLOAT64, lng FLOAT64>
LANGUAGE js AS """
if (!geohash) return null;
var base32 = '0123456789bcdefghjkmnpqrstuvwxyz';
geohash = geohash.toLowerCase();
var evenBit = true;
var latMin = -90, latMax = 90;
@vladaman
vladaman / eftpos-test.js
Created April 8, 2020 13:18
EFTPOS - Protocol test connection V. 3.00 (revision:07) - https://en.wikipedia.org/wiki/EFTPOS - simple test to communicate with MyPAX S800 Terminal
var net = require('net');
var HOST = '192.168.9.111';
var PORT = 20008;
const STX = 0x02; // Start transaction
const ETX = 0x03; // End transaction
const SEP = 0x1C; // Field separator
var client = new net.Socket();