Skip to content

Instantly share code, notes, and snippets.

View locnguyen's full-sized avatar

Loc Nguyen locnguyen

  • Southern California
  • X @locn
View GitHub Profile
@locnguyen
locnguyen / gitSearchMessages.js
Last active February 1, 2018 05:15
Search release branches by git commit messaage
const childProcess = require('child_process');
const { exec } = childProcess;
exec(`git log --oneline --all --grep "${process.argv[2]}"`, (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
const logResults = stdout.split('\n').filter(out => out.length).map(out => ({
sha: out.slice(0, 8),
@locnguyen
locnguyen / gist:7998611
Last active December 31, 2015 14:09
This is how I enable CORS in a Rails 4 application. The app is a JSON API consumed by an AngularJS front-end. Still a work in progress...
# Add a preflight check method and a set headers methond in ApplicationController
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :null_session
before_filter :set_cors_headers
before_filter :cors_preflight_check
@locnguyen
locnguyen / gist:7848265
Last active December 30, 2015 15:29 — forked from oisin/gist:6562181
Almost pulled all my hair out trying to figure out how to install the do_postgres gem with Postgres.app v9.3
gem install do_postgres -- --with-pgsql-server-dir=/Applications/Postgres93.app/Contents/MacOS --with-pgsql-server-include=/Applications/Postgres93.app/Contents/MacOS/include/postgresql/server
@locnguyen
locnguyen / rspec-syntax-cheat-sheet.rb
Created November 25, 2012 16:54 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
<ul>
<li ng-repeat="(key, errors) in myForm.$error track by $index">
<strong ng-bind="key"></strong> errors
<ul>
<li ng-repeat="e in errors">
<span ng-bind="e.$name"></span> has an error: <strong ng-bind="key"></strong>.
</li>
</ul>
</li>
</ul>
@locnguyen
locnguyen / vagrant_laravel.md
Last active August 29, 2015 14:05
Laravel Vagrant notes

Write permissions to app/storage need to be granted to the Vagrant VM. The gotcha is you have to do this from the host machine:

chmod -R 777 app/storage

For some reason ~/.composer (or COMPOSER_HOME) will change ownership to root:root. This needs to be owned by the vagrant user:

chown vagrant:vagrant ~/.composer

If you're still getting an exception when running composer install like this

@locnguyen
locnguyen / picard.php
Last active August 29, 2015 14:02
Picard ascii art for PHP
$picard = "
............................................________
....................................,.-'''...................``~.,
.............................,.-''...................................''-.,
.........................,/...............................................'':,
.....................,?......................................................,
.................../...........................................................,}
................./......................................................,:`^`..}
.............../...................................................,:''........./
..............?.....__.........................................:`.........../
@locnguyen
locnguyen / promises
Created April 7, 2014 04:23
Chaining AngularJS promises example
var loadClient = function () {
return currentUserService.getClient().then(function (client) {
$scope.client = client;
return client.id;
});
},
loadDefaultLastPeriod = function (clientId) {
return currentUserService.getScenarioByName({ clientId: clientId, name: 'Last Period' })
.then(function (scenario) {
$scope.defaultScenarios.push(scenario);
@locnguyen
locnguyen / gist:9540442
Created March 14, 2014 01:12
AngularJS directive for drag and drop file uploading
'use strict';
(function () {
angular.module('ui').directive('imageDrop', function () {
return {
restrict: 'EA',
scope: {
dropFn: '&'
},
link: function (scope, element, attrs) {