Skip to content

Instantly share code, notes, and snippets.

View raymondfeng's full-sized avatar

Raymond Feng raymondfeng

View GitHub Profile
@raymondfeng
raymondfeng / gist:6236245
Created August 14, 2013 22:20
Uninstaller for StrongLoop Node 1.1.x
#!/bin/sh
(( ${#} > 0 )) || {
echo 'StrongLoop Node Uninstall script based on original script courtesy of Nice Robot Co.'
echo 'Press Control-C to quit now.'
read
echo 'Re-running the script with sudo.'
echo 'You may be prompted for a password.'
sudo ${0} sudo
exit $?
}
a {
font-size: 200%;
color: rgb(0,128,0);
}
h1 {
border:5px solid red;
box-shadow: 10px 10px 5px #888888;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<input id='num' value=10>
<input id='answer' type='text' readonly>
@raymondfeng
raymondfeng / gist:8636789
Last active January 4, 2016 14:49
Tie-tac-toe homework
/**
* Check if the given slot is empty (no piece placed)
*/
function isEmpty(s) {
return s !== 'x' && s !== 'o';
}
/**
* Get the state for a row with three slots
*/
Statistical profiling result from /Users/rfeng/Demos/mssql-benchmark/v8-node-11.log, (114854 ticks, 208 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
208 0.2%
[Shared libraries]:
ticks total nonlib name
39 0.0% 0.0% /usr/lib/system/libsystem_pthread.dylib
33 0.0% 0.0% /usr/lib/system/libsystem_c.dylib
@raymondfeng
raymondfeng / gist:1637493e0fe12c1eade8
Created June 17, 2014 20:29
prototype properties
function X() {
}
Object.defineProperty(X.prototype, '__data',
{enumerable: false, configurable: true, writable: true, value: {x: 0}});
var x1 = new X();
console.log(Object.keys(x1));
console.log(x1.__data);
x1.__data = {x: 1};
@raymondfeng
raymondfeng / discovery-explorer.js
Created June 26, 2014 15:32
api explorer with discovered models
var loopback = require('loopback');
var path = require('path');
var app = module.exports = loopback();
var started = new Date();
/*
* 1. Configure LoopBack models and datasources
*
* Read more at http://apidocs.strongloop.com/loopback#appbootoptions
*/
module.exports = {
/**
* Declares a new hook to which you can add pres and posts
* @param {String} name of the function
* @param {Function} the method
* @param {Function} the error handler callback
*/
hook: function (name, fn, errorCb) {
if (arguments.length === 1 && typeof name === 'object') {
for (var k in name) { // `name` is a hash of hookName->hookFn
var loopback = require('loopback');
var path = require('path');
var app = module.exports = loopback();
app.set('restApiRoot', '/api');
var ds = loopback.createDataSource('soap',
{
connector: require('../index'),
@raymondfeng
raymondfeng / model-v2.js
Last active August 29, 2015 14:05
Generated loopback model from swagger api v2 specs
module.exports = function(Store) = {
/**
* Creates list of users with given input array
* @param {User} body List of user object
* @callback {Function} callback Callback function
* @param {Error|String} err Error object
* @param {Object} result Result object
*/
function createUsersWithListInput(body, callback) {