Skip to content

Instantly share code, notes, and snippets.

View vandershraaf's full-sized avatar

Muhammad Ashraf Ishak vandershraaf

View GitHub Profile
@vandershraaf
vandershraaf / malaysian_states_option_list.html
Last active April 3, 2023 21:28
List of Malaysian states in HTML <option> tag list (alphabetical order)
<option value="Johor">Johor</option>
<option value="Kedah">Kedah</option>
<option value="Kelantan">Kelantan</option>
<option value="Kuala Lumpur">Kuala Lumpur</option>
<option value="Labuan">Labuan</option>
<option value="Melaka">Melaka</option>
<option value="Negeri Sembilan">Negeri Sembilan</option>
<option value="Pahang">Pahang</option>
<option value="Penang">Penang</option>
<option value="Perak">Perak</option>
@vandershraaf
vandershraaf / RedisBinaryStore.java
Last active August 22, 2016 09:16
Storing binary file into Redis in Java
/**
* This example stores a binary file image ("Koala.jpg") into a local Redis server, and then
* retrieves it back which the finally written back to another file ("copyKoala.jpg")
*
* Dependencies: (Jedis and Commons IO)
*
* <dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.1</version>
@vandershraaf
vandershraaf / TestSecondaryReceiver.php
Created August 26, 2015 21:22
Adaptive payment with secondary receiver as fee payer
<?php
require_once('PPBootStrap.php');
require_once('Common/Constants.php');
$receiver = array();
// Receiver 1
$receiver[0] = new Receiver();
$receiver[0] -> email = "[email protected]";
$receiver[0] -> amount = 4.00;
@vandershraaf
vandershraaf / gist:5724297
Created June 6, 2013 19:39
Pattern.matcher doesnt throw NullPointerException
public long serializeTimestamp(String timeConfigFile, String key){
FileReader reader = null;
BufferedReader r = null;
FileWriter fw = null;
try {
reader = new FileReader(new File(timeConfigFile));
r = new BufferedReader(reader);
String line = r.readLine();
Pattern pattern = Pattern.compile("^"+key+"(\\d*)$");
Matcher matcher = pattern.matcher(line);
@vandershraaf
vandershraaf / gist:5084830
Created March 4, 2013 19:37
WHAT THE NULL??
In Java:
String test = "lala " + null;
System.out.println(test);
--> lala null
In Transact-SQL:
public class SimpleCounter {
public static int counter = 0;
public SimpleCounter(){
}
public void addOne(){
counter++;
}
@vandershraaf
vandershraaf / gist:4725826
Created February 6, 2013 21:04
Just don't use operator overload like this :(
Car mySedan = new Car();
Garage parkingGarage = new Garage();
mySedan = mySedan + parkingGarage; // park car in the garage
@vandershraaf
vandershraaf / gist:4504323
Created January 10, 2013 18:04
Internal code of HashMap.get()
public V get(Object key) {
if (key == null)
return getForNullKey();
int hash = hash(key.hashCode());
for (Entry<K,V> e = table[indexFor(hash, table.length)];
e != null;
e = e.next) {
Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
return e.value;
public class Library {
private static String libraryName;
private static List<String> books;
public boolean processBooks(){
for (String book: books){
if (book.equals(libraryName)){
return true;
}
}