Skip to content

Instantly share code, notes, and snippets.

Avatar

Loc Nguyen locnguyen

View GitHub Profile
@locnguyen
locnguyen / gitSearchMessages.js
Last active Feb 1, 2018
Search release branches by git commit messaage
View gitSearchMessages.js
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),
View gist:4ef7eeda8c029c214d10
# -*- 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.
View angularjs form errors
<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 Aug 29, 2015
Laravel Vagrant notes
View vagrant_laravel.md

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 Aug 29, 2015
Picard ascii art for PHP
View picard.php
$picard = "
............................................________
....................................,.-'''...................``~.,
.............................,.-''...................................''-.,
.........................,/...............................................'':,
.....................,?......................................................,
.................../...........................................................,}
................./......................................................,:`^`..}
.............../...................................................,:''........./
..............?.....__.........................................:`.........../
@locnguyen
locnguyen / promises
Created Apr 7, 2014
Chaining AngularJS promises example
View promises
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 Mar 14, 2014
AngularJS directive for drag and drop file uploading
View gist:9540442
'use strict';
(function () {
angular.module('ui').directive('imageDrop', function () {
return {
restrict: 'EA',
scope: {
dropFn: '&'
},
link: function (scope, element, attrs) {
@locnguyen
locnguyen / ConvertBase64ImageServiceObject
Created Mar 13, 2014
Service object for converting Base64 encoded image to save with Carrier Wave in Ruby apps
View ConvertBase64ImageServiceObject
# 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 Feb 28, 2014
Sample SignNow API usage
View gist:9280712
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 Dec 31, 2015
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...
View gist:7998611
# 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
You can’t perform that action at this time.