Skip to content

Instantly share code, notes, and snippets.

View seymores's full-sized avatar

Teo Choong Ping seymores

View GitHub Profile
@seymores
seymores / gist:c4f793e953f7d8623acb
Created March 17, 2015 03:03
Function to sanitize image file name to be web safe.
var safeImageURI = function(s) { return encodeURI(s).replace(/\-/g, "%2D").replace(/\_/g, "%5F").replace(/\./g, "%2E").replace(/\!/g, "%21").replace(/\~/g, "%7E").replace(/\*/g, "%2A").replace(/\'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29"); }
@seymores
seymores / mac-deals-scrapper.clj
Last active September 14, 2015 17:28
Mac refurbish deals scrapper
(ns mac-deals-checker.core
(:require [reaver :refer [parse extract-from text]]))
(def deal-url "http://www.apple.com/sg/shop/browse/home/specialdeals/mac")
(defn latest-deals-info
[]
(-> deal-url slurp parse (extract-from ".product" [:spec :price] "td.specs" text "span.current_price span span" text)))
@seymores
seymores / androidmanifest_decompressor.groovy
Created May 24, 2011 07:19
AndroidManifest.xml decompressor
// decompressXML -- Parse the 'compressed' binary form of Android XML docs
// such as for AndroidManifest.xml in .apk files
int endDocTag = 0x00100101;
int startTag = 0x00100102;
int endTag = 0x00100103;
public void decompressXML(byte[] xml) {
// Compressed XML file/bytes starts with 24x bytes of data,
// 9 32 bit words in little endian order (LSB first):
// 0th word is 03 00 08 00
/** E.g., UIColorFromRGB(0xE5E5E5) */
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@seymores
seymores / scala-2.9.1.final.rb
Created September 4, 2011 16:03
Homebrew formula to install Scala 2.9.1 final
require 'formula'
class ScalaDocs < Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/downloads/distrib/files/scala-2.9.1.final-devel-docs.tgz'
version '2.9.1'
md5 'acb16cbdf46f682806f60b052707b7b7'
end
class Scala < Formula
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
l = log --oneline --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
@seymores
seymores / haze-api.groovy
Last active December 19, 2015 02:19
Groovy script to get haza data from apims.doe.gov.my.
import org.jsoup.*
String URL = "http://apims.doe.gov.my/apims/hourly2.php"
def doc = Jsoup.connect(URL).get();
def result = doc.select("table.table1 tr");
result.each { tr ->
def row = tr.select("td")
println " ---- row---\n" + row[0].text() + " " + row[1].text()
@seymores
seymores / haze-api.clj
Created June 28, 2013 09:08
Get Haze API index with different libraries in clojure.
(ns haze-api.core
(:require [net.cgrand.enlive-html :as html])
(:gen-class))
(def doe-url "http://apims.doe.gov.my/apims/hourly2.php")
(defn rows-by-enlive
[url]
(let [site (html/html-resource (java.net.URL. url))
rows (html/select site [:table.table1 :tr])]
@seymores
seymores / gist:5972209
Last active December 19, 2015 14:49
Git config
#http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
[alias]
co = checkout
br = branch
ci = commit
st = status
last = log -1 HEAD
visual = !gitk
l = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
@seymores
seymores / gist:6208758
Created August 12, 2013 07:09
Clojure namespace
This is all you need to know about Clojure’s namespace declarations:
(ns my-project.core
; :require Clojure libs
(:require clojure.core.async
[compojure.core :refer [POST routes]]
[compojure.handler :refer :all]
[ring.adapter.jetty :as jetty]
[clojure.edn :as edn :refer [read]])
; :import for Java classes