Skip to content

Instantly share code, notes, and snippets.

View icchan's full-sized avatar

Ian icchan

View GitHub Profile
@icchan
icchan / canvas-spiral.html
Last active October 14, 2018 05:30
Drawing a spiral on the HTML5 canvas using javascript
<!DOCTYPE HTML>
<html><body>
<canvas id="myCanvas" width="300" height="300" style="border:1px solid #c3c3c3;"></canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
var centerX = 150;
var centerY = 150;
cxt.moveTo(centerX, centerY);
@icchan
icchan / go-decryption.go
Last active August 29, 2015 14:05
Function to decrypt an aes encrypted and base64 encoded string
func decrypter(crypto string, keyString string) string {
paddedKey := fmt.Sprintf("%-16s", keyString) // 16 bytes
key := []byte(paddedKey)
bc, err := aes.NewCipher(key)
if err != nil {
fmt.Println(err)
}
src, _ := hex.DecodeString(crypto)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
@icchan
icchan / geospatial-querying-with-go-and-mongodb.go
Created October 18, 2014 07:37
Geospatial Querying with GoLang and MongoDB
package main
import (
"encoding/json"
"fmt"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"log"
)
@icchan
icchan / RegexCardValidator.java
Last active May 16, 2024 04:13
Java Credit Card Number Validator
package net.bubblemix.cardcheck;
/**
* Validator for credit card numbers
* Checks validity and returns card type
*
* @author ian.chen
*/
public class RegexCardValidator {
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.http.HttpStatus;
@icchan
icchan / EmbeddedCassandraTest.java
Created November 17, 2015 07:10
Embedded Cassandra Spring JUnit Test
package net.bubblemix.test;
import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@icchan
icchan / ian-svg.html
Last active November 20, 2015 03:05
A svg of the ian hair logo
<html>
<head>
<style>
#ian {
position: absolute;
bottom: 0px;
height: 400px;
}
body {
background: #eef;
package main
import (
"fmt"
"golang.org/x/crypto/ripemd160"
)
func main() {
hasher := ripemd160.New()
hasher.Write([]byte("The quick brown fox jumps over the lazy dog"))
@icchan
icchan / LoggerFilter.java
Created February 19, 2016 10:19
A filter for logging the HTTP header and body, but allowing it to be read again in the next filter, servlet or controller
package net.bubblemix;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;