Skip to content

Instantly share code, notes, and snippets.

View zynick's full-sized avatar
🤖

Chan Zi-Yuan zynick

🤖
View GitHub Profile
@zynick
zynick / GuessRandom.java
Last active December 16, 2015 17:09
Prove that java.util.Random isn't that random after all...
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
* in response to http://jazzy.id.au/default/2010/09/20/cracking_random_number_generators_part_1.html
* <p>
* the code on that website works 1 out of 4 times because, as mentioned by the
* author itself, it isn't complete since he prefer to keep the code easier to
* read and understand.
* <p>
@zynick
zynick / ConcurrentTest.java
Created May 15, 2013 14:53
concurrent test sample
package test.thread;
import java.util.ArrayList;
public class ConcurrentTest {
public static void main(String[] args) throws Exception {
new ConcurrentTest().execute();
}
package com.zynick.mongo;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
@zynick
zynick / bash_profile
Created July 12, 2014 03:56
My Personal Bash Profile
# Colors
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\[\e[0;31m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
# Configure PATH
# - These are line by line so that you can kill one without affecting the others.
# - Lowest priority first, highest priority last.
export PATH=$PATH
export PATH=$HOME/bin:$PATH
@zynick
zynick / download-file.js
Created January 6, 2016 12:17
download file ('save as') using javascript xhr
// http://stackoverflow.com/a/23797348/1150427
xhr.open('POST', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (this.status === 200) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
@zynick
zynick / XORCipher.js
Last active June 5, 2017 01:04 — forked from sukima/XORCipher.js
A Super simple encryption cipher using XOR and Base64 in JavaScript (No Dependency)
// Modified: Removes dependency on [Underscore](http://underscorejs.org/)
// so you can copy the following code and use it everywhere (even in browser console!)
//
// XORCipher - Super simple encryption using XOR and Base64
//
// As a warning, this is **not** a secure encryption algorythm. It uses a very
// simplistic keystore and will be easy to crack.
//
// The Base64 algorythm is a modification of the one used in phpjs.org
// * http://phpjs.org/functions/base64_encode/
@zynick
zynick / .screenrc
Created August 8, 2018 07:30 — forked from joaopizani/.screenrc
A killer GNU Screen Config
# the following two lines give a two-line status, with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%? %1`%?%{g}][%= %{= kw}%-w%{+b yk} %n*%t%?(%u)%? %{-}%+w %=%{g}][%{B}%m/%d %{W}%C%A%{g}]'
# huge scrollback buffer
defscrollback 5000
# no welcome message
startup_message off