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),
# -*- 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) {
@locnguyen
locnguyen / ConvertBase64ImageServiceObject
Created March 13, 2014 23:06
Service object for converting Base64 encoded image to save with Carrier Wave in Ruby apps
# Needed for Rails 3+
class FilelessIO < StringIO
attr_accessor :original_filename
end
class ConvertBase64ImageService
def call(base64_encoded_image, filename)
@locnguyen
locnguyen / gist:9280712
Created February 28, 2014 21:48
Sample SignNow API usage
Create a new user with base 64 encoded client credentials...
curl -H 'Authorization: Basic MGZjY2RiYzczNTgxY2EwZjliZjhjMzc5ZTZhOTY4MTM6MzcxOWExMjRiY2ZjMDNjNTM0ZDRmNWMwNWI1YTE5NmI=' --data '{"email":"lnguyen@mailinator.com", "password": "x"}' -X POST https://capi-eval.signnow.com/api/user
Create an oauth2 token for the new user
curl -H 'Authorization: Basic MGZjY2RiYzczNTgxY2EwZjliZjhjMzc5ZTZhOTY4MTM6MzcxOWExMjRiY2ZjMDNjNTM0ZDRmNWMwNWI1YTE5NmI=' --data 'username=lnguyen@mailinator.com&password=x&scope=*&grant_type=password' https://capi-eval.signnow.com/api/oauth2/token
Create a new document for that user with his oauth2 token
curl -H 'Authorization: Bearer be933cbc0ebe63f8d636a517f23feb4826ceef67b5f29a12896d40cd0e9dd4c0' -F 'file=snlogo.png' https://capi-eval.signnow.com/api/document
Get a list of the user's documents
@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