Skip to content

Instantly share code, notes, and snippets.

View alexpchin's full-sized avatar

Alex Chin alexpchin

View GitHub Profile
@alexpchin
alexpchin / ultimate-ut-cheat-sheet.md
Created February 13, 2016 18:51 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies


@alexpchin
alexpchin / geocoder-service.js
Created February 11, 2016 22:46 — forked from benmj/geocoder-service.js
An AngularJS Service for intelligently geocoding addresses using Google's API. Makes use of localStorage (via the ngStorage package) to avoid unnecessary trips to the server. Queries Google's API synchronously to avoid `google.maps.GeocoderStatus.OVER_QUERY_LIMIT`
/*global angular: true, google: true, _ : true */
'use strict';
angular.module('geocoder', ['ngStorage']).factory('Geocoder', function ($localStorage, $q, $timeout) {
var locations = $localStorage.locations ? JSON.parse($localStorage.locations) : {};
var queue = [];
// Amount of time (in milliseconds) to pause between each trip to the
@alexpchin
alexpchin / rspec_rails_cheetsheet.rb
Created February 9, 2016 18:42 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@alexpchin
alexpchin / gulpfile.js
Created January 20, 2016 13:56 — forked from edouard-lopez/gulpfile.js
Gulp copy font-awesome files to dist/ directory
'use strict';
// Generated on 2014-04-14 using generator-leaflet 0.0.14
var gulp = require('gulp');
var open = require('open');
var wiredep = require('wiredep').stream;
// Load plugins
var $ = require('gulp-load-plugins')();
@alexpchin
alexpchin / gulpfile.js
Created January 16, 2016 17:45 — forked from vincent-zurczak/gulpfile.js
Copy minified Bower dependencies with Gulp (better solution)
// Include our plug-ins
var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');
var exists = require('path-exists').sync;
// Create some task
gulp.task( 'copy-bower-dep', function() {
// Replace files by their minified version when possible
var bowerWithMin = mainBowerFiles().map( function(path, index, arr) {
@alexpchin
alexpchin / oauth_twit_consume_example.js
Created January 6, 2016 11:46 — forked from tomshaw/oauth_twit_consume_example.js
Some Node.js Express, Jade, examples using Node-OAuth querying protected Twitter consumer resources.
function consumer() {
return new oauth.OAuth(
"https://twitter.com/oauth/request_token",
"https://twitter.com/oauth/access_token",
keys.twitterConsumerKey,
keys.twitterConsumerSecret,
"1.0A",
"http://localhost:3000/sessions/callback",
"HMAC-SHA1"
);
@alexpchin
alexpchin / socket-cheatsheet.js
Created December 15, 2015 16:58
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
@alexpchin
alexpchin / serialize.js
Created December 14, 2015 14:35
Serialize Javascript
function serialize(obj) {
var str = [];
for(var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}
module.exports = serialize;
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
files: {
'public/css/style.css' : 'public/scss/style.scss'
}
}
},
@alexpchin
alexpchin / gist:8f175cad3e4864c894a3
Created November 1, 2015 20:45
Wordpress Setup on mac
Start Mamp
Start MySQL with:
```
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart
```