Skip to content

Instantly share code, notes, and snippets.

View geeknam's full-sized avatar

Nam Ngo geeknam

View GitHub Profile
@geeknam
geeknam / git_history.php
Created May 8, 2011 16:43
Parse git log with PHP to an array
<?php
// Author: Ngo Minh Nam
$dir = "/path/to/your/repo/";
$output = array();
chdir($dir);
exec("git log",$output);
$history = array();
foreach($output as $line){
if(strpos($line, 'commit')===0){
@geeknam
geeknam / cognitoupload.py
Created April 2, 2017 07:13
Upload file to S3 with an authenticated Cognito User
import boto3
import uuid
class CognitoUserFileUploader(object):
def __init__(self, *args, **kwargs):
self.__dict__.update(kwargs)
self.id_token = self.get_cognito_id_token(
self.username, self.refresh_token,
self.device_key, self.client_id
@geeknam
geeknam / .tmux.conf
Last active November 28, 2018 12:37
my tmux.conf
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
setw -g mode-keys vi
set -g default-terminal 'screen-256color'
set -g history-limit 10000
# Setup 'v' to begin selection as in Vim
@geeknam
geeknam / .zshrc
Last active October 23, 2018 08:13
Standard .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/nam/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="simple"
@geeknam
geeknam / snsasync.py
Created February 20, 2017 03:52
Serverless async task via SNS
import os
import json
import importlib
import inspect
import boto3
SNS_ARN = os.environ.get('SNS_ARN', None)
def import_and_get_task(task_path):
// for more debug logging, add this to ./conf/log4j-console.properties
// log4j.logger.com.thinkaurelius.titan.graphdb.database.management=DEBUG
// Open the graph
graph = TitanFactory.build().set('storage.backend','inmemory').set('schema.default','none').set('query.force-index',true).open();
g = graph.traversal()
// Create an index on new property key. Index created on new property is ENABLED immediately.
if (graph.getOpenTransactions()) graph.tx().rollback()
mgmt = graph.openManagement()
@geeknam
geeknam / middleware.py
Last active January 18, 2017 23:25
Handy Django 1.10 middleware classes for Zappa
# NOTE: these are Django new style middleware classes, won't work with
# Django < 1.10
from django.conf import settings
ACAH = [
'Content-Type', 'X-Amz-Date', 'Authorization',
'X-Api-Key', 'X-Amz-Security-Token', 'x-requested-with',
]
@geeknam
geeknam / macsetup.sh
Last active December 14, 2016 13:15
Mac setup
#!/bin/bash
# Python stuff
sudo easy_install pip
sudo pip install virtualenvwrapper --ignore-installed six
# Sublime cli
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
# Brew and stuff
@geeknam
geeknam / 0_reuse_code.js
Created October 5, 2013 14:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@geeknam
geeknam / pyrefactors.py
Created November 6, 2012 09:22
Python refactors
"""
Use setattr
"""
# Normal
item.price = self.request['price']
item.quantity = self.request['quantity']
item.shipping = self.request['shipping']
item.save()