Skip to content

Instantly share code, notes, and snippets.

View cheeming's full-sized avatar

Chew Chee Ming cheeming

View GitHub Profile
@cheeming
cheeming / csrf_ajax.js
Created January 17, 2017 14:45
Additional AJAX code setup for CSRF for jQuery
_getCookie = null;
$(function () {
// *** CSRF starts
// ref: https://docs.djangoproject.com/en/1.6/ref/contrib/csrf/#ajax
// ----------------------------------------------------
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
@cheeming
cheeming / delete_domain_permission.py
Created June 23, 2015 11:24
Recursively change the files in your Google Drive folder to be private (only specific people can access) instead of anyone at domain can find and view
"""Delete domain permission from your Google Drive files.
The reason why I created this script is so that I can use this script to
recursively remove the domain permission item from all files.
By default, Google Drive will share files to all users in the domain (this
setting is recognised as the domain permission type for the file in
Google Drive). I don't really want certain files to be shared this way, but
there is no easy way recursively fix this in Google Drive, so that is why
this script is created.
@cheeming
cheeming / making-jquery-mobile-page-transitions-work-well-with-android-4.1.md
Last active August 29, 2015 14:18
Making jQuery Mobile page transitions work well with Android 4.1
  • We are using:
    • Cordova v4.3.0
    • jQuery Mobile v1.4.5
  • We would like page transitions to be animated nicely
  • Android 4.1 doesn't play ball
  • We use the standard jQuery Mobile pages with fixed header, and we've disabled tap toggle
  • We find that we get 2 problems
    • White flashes, flickering, in between the page transitions
    • Also the content of the page gets pushed underneath the fixed header, when we remove previously inserted pages (we do this to deal with memory / performance issues)
  • And user is able to tap hold and prompt up the user selection options / widgets, i.e. copy and paste
@cheeming
cheeming / publish-ios-to-itunes.md
Last active October 15, 2015 08:27
Publishing your iOS app to iTunes

Publishing to iTunes

  • Login to https://developer.apple.com/
    • Click on iOS Dev Center
    • Click on Certificates, Identifiers & Profiles
    • Ensure that there is:
      • Under Certificates (Production), a certificate for iOS Distribution
        • To create a Certificate (Signing Identity), one needs to create a Certificate Signing Request
        • You can do this with Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority
  • The Certificate comes with private key and public key, normally the private key would be stored in the machine that generated the initial request
@cheeming
cheeming / download_main_page_articles.js
Last active August 29, 2015 14:06
Download current HackerNews articles into PDF (CasperJS)
// tested with casperjs v1.1.0-beta3 and phantomjs v1.9.7
var casper = require('casper').create({
viewportSize: {width: 1024, height: 768}
});
casper.start('https://news.ycombinator.com/', function() {
this.capture('hackernews-main.pdf');
var links = this.evaluate(function() {
var l = document.querySelectorAll("td[class=title] a");
var r = [];
# the following is one way to generate self-signed cert for this test server
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
from http.server import HTTPServer,SimpleHTTPRequestHandler
from socketserver import BaseServer
import ssl
HOSTNAME = 'localhost'
HTTPS_PORT = 8443
httpd = HTTPServer((HOSTNAME, HTTPS_PORT), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='server.key', certfile='server.crt', server_side=True)
@cheeming
cheeming / gist:c93aa22c4e302a9ab8ef
Last active August 29, 2015 14:05
Gimp ScriptFu - Colorify your Image
; run the script in interactive gimp batch mode
; i.e.:
; $ gimp -i -b -
; copy and paste the following into the interactive shell
; do note that the code is Scheme, so you got to learn a new language ;)
(define (ccm-colorify filename
color)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
@cheeming
cheeming / download_hacker_monthly.py
Created July 3, 2014 16:20
Download All Hacker Monthly Issues
from BeautifulSoup import BeautifulSoup
from urllib2 import build_opener
from os import path
HMSUB_SESSION_COOKIE = 'XXX'
o = build_opener()
o.addheaders.append(
('Cookie', '_hmsub_session=%s' % HMSUB_SESSION_COOKIE),
)
@cheeming
cheeming / BorangEA.tex
Created March 22, 2014 16:39
Borang EA - Latex format
\documentclass[a4paper,10pt]{article}
\usepackage[margin=1.2cm]{geometry}
\usepackage{graphicx}
\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{eso-pic}
\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
@cheeming
cheeming / patch-fix-slave-ok-flag.diff
Created August 5, 2012 11:28
Patch to fix mongo c driver to allow connection to secondary/slave mongodb instances. This patch will apply cleanly on revision 13808396bd1b128dfa03ea3ba4d3cdccb9d990c7 for https://github.com/mongodb/mongo-c-driver
diff --git a/src/gridfs.c b/src/gridfs.c
index f51b397..66f8d88 100644
--- a/src/gridfs.c
+++ b/src/gridfs.c
@@ -43,7 +43,7 @@ int gridfs_init( mongo *client, const char *dbname, const char *prefix,
int options;
bson b;
- bson_bool_t success;
+ bson_bool_t success = 1;