Skip to content

Instantly share code, notes, and snippets.

View chinying's full-sized avatar
🙃

Seah Chin Ying chinying

🙃
View GitHub Profile
@chinying
chinying / random_generator.py
Created October 12, 2016 15:25
when you need dummy data
import string, random
letters = (list(string.ascii_letters))
numbers = [n for n in string.digits]
alphanumeric = (letters + numbers)
genlen = 12
result = random.sample(alphanumeric, genlen)
print("".join(result))
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.LinkedList;
import java.util.Stack;
/*
* WIP : order based methods
* min, max, floor, ceiling, selection
@chinying
chinying / Huffman.java
Created October 19, 2015 15:22
very crude huffman but it works for now
import java.io.*;
import java.util.*;
public class Huffman{
private int N;
private PriorityQueue<Node> pq;
private Node root;
public Huffman(String[] s, int[] freq){
N = s.length;
@chinying
chinying / gist:e1b99a6a033455a8457a
Last active August 29, 2015 14:20
so i had this question for my finals today : take 3 integers from the command line and print them in descending order. i did it without sorting :)
class f{
public static int max(int x, int y){
return (x > y) ? x : y;
}
public static int min(int x, int y){
return (x < y) ? x : y;
}
public static void main(String [] args){
#include <cstdio>
#include <cmath>
typedef long long ll;
//Returns length of integer
int len(int n){
return (n == 0 ? 1 : (int)(log10(n)+1));
}
@chinying
chinying / anagram checker
Created May 5, 2015 13:10
checks if 2 strings are permutations of each other aka anagrams
public static boolean checkAnagram(String s1, String s2){
if (s1.length() != s2.length()) return false;
int wt1 = 0, wt2 = 0, i;
for (i=0; i<s1.length(); i++) wt1+=(int)(s1.charAt(i));
for (i=0; i<s2.length(); i++) wt2+=(int)(s2.charAt(i));
return wt1 == wt2;
}