Skip to content

Instantly share code, notes, and snippets.

Ben Ng ben-ng

Block or report user

Report or block ben-ng

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ben-ng
ben-ng / try-1.txt
Last active Dec 5, 2016
Swift build failure logs
View try-1.txt
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-31-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
100 packages can be updated.
47 updates are security updates.
@ben-ng
ben-ng / mergesort.swift
Created Dec 1, 2016
Benchmarking improvements to the ArrayElementValuePropagation pass
View mergesort.swift
import Cocoa
func mergeSort(_ array: [Int]) -> [Int] {
guard array.count > 1 else { return array }
let middleIndex = array.count / 2
let leftArray = mergeSort(Array(array[0..<middleIndex]))
let rightArray = mergeSort(Array(array[middleIndex..<array.count]))
return merge(leftPile: leftArray, rightPile: rightArray)
}
@ben-ng
ben-ng / roman.py
Created Sep 21, 2016
Sample solution for converting roman numerals to integers
View roman.py
def convert(char):
return {
'M': 1000,
'D': 500,
'C': 100,
'L': 50,
'X': 10,
'V': 5,
'I': 1
}.get(char)
View 1-README.md

Tasks

Before you start

Depending on your assigned system, read the README-ORACLE.md or README-POSTGRES.md file.

You might need to configure user accounts and permissions to accomplish these tasks.

Tasks

View keybase.md

Keybase proof

I hereby claim:

  • I am ben-ng on github.
  • I am benng (https://keybase.io/benng) on keybase.
  • I have a public key ASDpep_MuCxliK8Ty1NbkbFqxaqIh4dbgrd1NNpMoUV3tQo

To claim this, I am signing this object:

@ben-ng
ben-ng / server.js
Created Jun 4, 2015
A simple, slow server for testing deis' zero downtime deploys
View server.js
setTimeout(function () {
require('http').createServer(function (req, res) {
res.end('yo!')
}).listen(process.env.PORT)
}, 45000)
@ben-ng
ben-ng / gist:297cc283f04638005048
Last active Aug 29, 2015
setTimeout without setTimeout
View gist:297cc283f04638005048
/**
* Just call __PBSJC_drain at the end of your code
*/
var __PBSJC_funcHandles = []
, __PBSJC_funcHandleCount = 0
, __PBSJC_drain = function __PBSJC_drain () {
var extracted, i, ii, cur
while (__PBSJC_funcHandles.length) {
extracted = __PBSJC_funcHandles
View deeplink.js
@ben-ng
ben-ng / Readme.md
Created Nov 15, 2014
How should I do this?
View Readme.md

If you're interested in my OTA update system for iOS PhoneGap apps, let me know how you think I should release it, and why:

(Sorted in order from "it just works" to "most flexible, but requires deeper knowledge of iOS apps")

  • A CLI tool that patches an app (you would run this on platforms/ios)
  • A complete PhoneGap iOS application (you would clone this repo and edit it to your tastes)
  • The update logic only, as a library (I'd provide example replacements for MainViewController.m, AppDelegate.m)
  • Other (I'm not a huge fan of any of these, so I'm open to suggestions)
@ben-ng
ben-ng / fixPrefixes.m
Created Nov 14, 2014
Use UIWebView's `loadHTMLString:baseURL:` and set the baseURL to where your assets are in the app bundle. Then replace all absolute paths in your html/js/css with relative ones using something like the script below. The relative URLs will be loaded relative to the baseURL, whereas absolute ones are loaded relative to the root of the filesystem, …
View fixPrefixes.m
// This doodad converts absolute paths like "/assets/thing.jpg" into relative ones like "assets/thing.jpg"
NSString * (^fixPrefix)(NSString *, NSString *) = ^NSString *(NSString * input, NSString *prefix) {
NSString *needle = [[@"/" stringByAppendingString:prefix] stringByAppendingString:@"/"];
NSString *replacement = [prefix stringByAppendingString:@"/"];
input = [input stringByReplacingOccurrencesOfString:[@"'" stringByAppendingString:needle] withString:[@"'" stringByAppendingString:replacement]];
input = [input stringByReplacingOccurrencesOfString:[@"\"" stringByAppendingString:needle] withString:[@"\"" stringByAppendingString:replacement]];
input = [input stringByReplacingOccurrencesOfString:[@"(" stringByAppendingString:needle] withString:[@"(" stringByAppendingString:replacement]];
return input;
You can’t perform that action at this time.