Skip to content

Instantly share code, notes, and snippets.

View geeknam's full-sized avatar

Nam Ngo geeknam

View GitHub Profile
// 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 / 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 / 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):
@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 / .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 / 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 / .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 / psa_mobile.py
Created November 2, 2014 12:10
python-social-auth mobile support
from social.actions import do_complete
from social.apps.django_app import load_strategy
from social.apps.django_app.default.models import UserSocialAuth
from social.apps.django_app.views import _do_login
from social.backends.utils import load_backends
from social.exceptions import MissingBackend
def psa_mobile(request, *args, **kwargs):
from fabric.api import env, local, require
def deploy():
"""fab [environment] deploy"""
require('environment')
maintenance_on()
push()
syncdb()
migrate()
@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