Skip to content

Instantly share code, notes, and snippets.

package com.thoughtmonkeys.pitstop;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
@ruiwen
ruiwen / command.sh
Last active May 8, 2022 07:26
Obtain Base64-encoded SHA256 hash of a servers OpenSSL pubkey used with `curl`'s `--pinnedpubkey`
# Obtaining server certificate
openssl s_client -CAfile ca.crt -connect "server.domain.com:443" < /dev/null 2> /dev/null | openssl x509 -outform PEM > server.crt
# You may get an error like the following
# CONNECTED(00000003)
# 140048174458520:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:
# ---
# no peer certificate available
# ---
# No client certificate CA names sent
function rainbow(numOfSteps, step) {
// based on http://stackoverflow.com/a/7419630
// This function generates vibrant, "evenly spaced" colours (i.e. no clustering). This is ideal for creating easily distiguishable vibrant markers in Google Maps and other apps.
// Adam Cole, 2011-Sept-14
// HSV to RBG adapted from: http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
var r, g, b;
var h = step / numOfSteps;
var i = ~~(h * 6);
var f = h * 6 - i;
var q = 1 - f;
@ruiwen
ruiwen / parseProfile.py
Created October 3, 2012 12:43
Map-reduce in with MongoDB with PyMongo for Parse timing calls
'''
Sample object:
{
"url": "/1/functions/Klass3",
"_id": {
"$oid": "506c082701d5410ec7000002"
},
"log": [
{
@ruiwen
ruiwen / keybase.md
Last active September 19, 2017 01:56
keybase.md

Keybase proof

I hereby claim:

  • I am ruiwen on github.
  • I am ruiwen (https://keybase.io/ruiwen) on keybase.
  • I have a public key ASC6hOGJ6j8XRLof2za5Fe_gXhtXOOo42WrNt_6tH-W3Bwo

To claim this, I am signing this object:

@ruiwen
ruiwen / keybase.md
Created September 19, 2017 01:54
keybase.md

Keybase proof

I hereby claim:

  • I am ruiwen on github.
  • I am ruiwen (https://keybase.io/ruiwen) on keybase.
  • I have a public key ASC6hOGJ6j8XRLof2za5Fe_gXhtXOOo42WrNt_6tH-W3Bwo

To claim this, I am signing this object:

@ruiwen
ruiwen / fb-angular.js
Last active July 5, 2017 10:40
Wrapping and initialising the Facebook SDK with Angular JS
// Facebook SDK
angular.module('facebook', [])
.directive('fb', ['$FB', function($FB) {
return {
restrict: "E",
replace: true,
template: "<div id='fb-root'></div>",
compile: function(tElem, tAttrs) {
return {
post: function(scope, iElem, iAttrs, controller) {
package com.thoughtmonkeys.pitstop;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
@ruiwen
ruiwen / redis_pipeline.sh
Created March 23, 2017 06:25
Bash function to translate redis commands to their pipelined equivalent
# Bash function to translate redis commands to their pipelined equivalent
#
# eg.
#
# $ redis_p HMSET key value key1 value1
# *5
# $5
# HMSET
# $3
# key
  • Unit

    • migrate listers rm_prefs into self.hm_prefs
      • Note this migration needs to take place before the User migration below (due to migration of rm_prefs and hm_prefs
  • User

    • rename rm_prefs -> hm_prefs (ie. copy values over)
      • delete rm_prefs on User if need be
    • copy all user.personal attributes onto user (top-level)
      • age = IntField()
  • gender = StringField(choices=['male', 'female', 'third'], default="female")