Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@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
@ruiwen
ruiwen / Video wall.markdown
Last active October 20, 2015 05:28
Video wall
@ruiwen
ruiwen / sq-content.d.coffee
Created August 11, 2015 10:01
AngularJs directive for dynamically adjusting an element's height to fill the vertical height of the page
angular.module('utils')
.directive('sq-content', [
'$log'
'$window'
($log, $window) ->
restrict: 'A'
link: (scope, elem, attrs) ->
# Calculates and sets the height of element to fully take up
# the rest of the vertical height in a page
# Mainly used for activating overflow: scroll for md-content
function keypress(n) {
var keyboardEvent = new KeyboardEvent('keydown', {bubbles:true});
Object.defineProperty(keyboardEvent, 'charCode', {get:function(){return this.charCodeVal;}});
Object.defineProperty(keyboardEvent, 'keyCode', {get: function(){return this.charCodeVal;}});
keyboardEvent.charCodeVal = n;
document.body.dispatchEvent(keyboardEvent);
}
@ruiwen
ruiwen / enum.js
Last active October 5, 2015 07:04
Enums
function Enum() {
var self = this;
var vals = {};
for(var i=0; i < arguments.length; ++i) {
vals[arguments[i]] = i == 0? 0 : Math.pow(2, i-1)
vals[i] = i == 0? 0 : Math.pow(2, i-1)
Object.defineProperty(self, arguments[i], {
'value': vals[arguments[i]],
})
}
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;
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;