Skip to content

Instantly share code, notes, and snippets.

View kenchangh's full-sized avatar
🎀

Ken Chan kenchangh

🎀
  • World
View GitHub Profile
@kenchangh
kenchangh / progress_bar.py
Created May 11, 2014 09:49
Python - Progress Bar
import sys
def progress_bar(list_size):
# list_size takes an integer as parameter
lst = range(list_size)
for index, item in enumerate(lst):
# List index starts from 0
# Round position / size of list to 1 decimal place
# 0.567777 => 0.57
# Multiplied by 100 to give you the percentage!
@kenchangh
kenchangh / .emacs
Created May 12, 2014 16:25
My .emacs file
;; General Emacs settings
(set-default 'cursor-type 'bar)
(setq-default indent-tabs-mode nil) ; always replace tabs with spaces
(setq-default tab-width 8) ; set tab width to 4 for all buffers
(add-hook 'lisp-mode-hook '(lambda ()
(local-set-key (kbd "RET") 'newline-and-indent)))
(setq make-backup-files nil) ; No #backup-files# will be made anymore
(setq backup-inhibited t) ;disable backup
(setq auto-save-default nil) ;disable auto save
@kenchangh
kenchangh / github-create.sh
Last active August 29, 2015 14:02
github-create.sh
github-create() {
echo "Enter your new GitHub repository's name: "
read repo_name
echo 'Sending requests to GitHub to create repository...'
curl -u 'guanhao97:9f733ad9a8cca515a8c8ad3a67a6f1a9c6ec488b' https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
cd /home/guanhao97/Desktop/$repo_name
echo 'New local repository? (y/n)'
read new_local
if [ $new_local == 'y' ]
then
@kenchangh
kenchangh / hot_score.py
Created June 28, 2014 17:48
Hot Ranking Algorithm
##########
from math import log10
from datetime import datetime
##########
SET_TIME = 1403975999.39
def epoch_seconds(date):
@kenchangh
kenchangh / auth.py
Created June 30, 2014 09:22
A simple authentication / sign up / login system implemented in Google App Engine Python
##########
import json
import hmac
import logging
from hashlib import sha256
from utils.validate import make_salt, make_cookie
from utils.validate import SafeLogin
@kenchangh
kenchangh / validate.py
Created June 30, 2014 09:29
Validation methods in Google App Engine
##########
import re
import hmac
import random
from hashlib import sha256
from base_handler import BaseHandler
from google.appengine.ext import db
@kenchangh
kenchangh / prom_vote.py
Created July 4, 2014 17:41
A script that automates Prom King / Queen voting for SMK Damansara Jaya
import requests
import thread
def make_vote(gender):
if gender == 'f':
url = 'https://docs.google.com/forms/d/1RBXC6SrZ9D86qksVVlfybfNBi-zEG9npsIHWWNas8JM/formResponse'
form_data = {
'entry.1739159996': 'Karina Lee -5 Bal'
}
@kenchangh
kenchangh / hot_score.jl
Last active August 29, 2015 14:04
A rewrite of the hot score algorithm in Julia
# The epoch seconds when the algorithm is implemented
const SET_TIME = 1403975999.39
function hot(score, created, comments, user_rep)
# To make the score scale smaller
score = log10(abs(score))
if score > 0
sign = 1
elseif score < 0
sign = -1
@kenchangh
kenchangh / variable_styles.md
Last active August 29, 2015 14:04
Julia's style conventions for variables.

Stylistic Conventions

While Julia imposes few restrictions on valid names, it has become useful to adopt the following conventions:

  • Names of variables are in lower case.
  • Word separation can be indicated by underscores ('_'), but use of underscores is discouraged unless the name would be hard to read otherwise.
  • Names of Types begin with a capital letter and word separation is shown with CamelCase instead of underscores.
  • Names of functions and macros are in lower case, without underscores.
  • Functions that modify their inputs have names that end in !. These functions are sometimes called mutating functions or in-place functions.
@kenchangh
kenchangh / practice.jl
Last active August 29, 2015 14:04
A practice on Julia.
# This is just for practice!
# Single line comment
#=
This is a multiline comment
=#
# Function syntax
function name(x, args...)
# do something