Skip to content

Instantly share code, notes, and snippets.

View geeknam's full-sized avatar

Nam Ngo geeknam

View GitHub Profile
geeknam /
Created January 13, 2011 15:08
Get Email of user from xmpp_handlers.CommandHandler
class XMPPHandler(xmpp_handlers.CommandHandler):
def text_message(self, message):
idx = message.sender.index('/')
user = message.sender[0:idx]
geeknam /
Created January 13, 2011 15:12
A simple implementation of web service using Google App Engine
import urllib
import json
from google.appengine.api import mail
from google.appengine.ext import webapp, db
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp.util import run_wsgi_app
class Feedback(db.Model):
user = db.StringProperty()
geeknam / getpic.js
Created January 13, 2011 15:17
Chrome Extension to get RP pics
function showPic(){
function getPic(){
var idval = $("#studentId").val();
var nameval = $("#fullname").val();
url = '<img src="Directory of the schools site that pictures resides at' + idval + '-' + nameval + '.jpg" onerror="notFound()"/>';
geeknam / rpavatar.html
Created January 13, 2011 15:19
HTML skeleton of Chrome Extension
<link type="text/css" href="style.css" rel="stylesheet" />
<script src="jquery.js"></script>
<script src="getpic.js"></script>
<div id="header">
<a href="" target="_blank">Login here</a>
before using this extension
site = SitesApp.getSite("", "sitesdemo"); // domain and site's name (url)
list = site.getListPages(); //get all ListPages and store inside an array
function updateList(){
var sheet = SpreadsheetApp.getActiveSheet(); //get the Spreadsheet that the script is executed from
var startRow = 2;
var numRows = sheet.getLastRow()-1; //get number of rows to fetch data
var dataRange = sheet.getRange(startRow,1,numRows,3); //range based on A1 notation
var data = dataRange.getValues();
var columns = ["Name","Email"]; //column names in the ListPage
geeknam / internet_sharing.scpt
Created March 5, 2011 18:36
Applescript to activate Internet Sharing
growlnote("Copying process", "bootpd.plist copied")
do shell script "sudo cp /tmp/bootpd.plist /etc" password "yourpassword" with administrator privileges
tell application "System Preferences" to set current pane to pane ""
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1 of window "Sharing"
delay 1
if (exists sheet 1 of window "Sharing") then
click button "Start" of sheet 1 of window "Sharing"
end if
geeknam / git-pull-all.php
Created April 16, 2011 17:20
Executes 'git pull' in all directories
/* Author: Ngo Minh Nam */
$dirs = array_filter(glob(dirname(__FILE__)."/*"), 'is_dir');
foreach($dirs as $dir){
$output = shell_exec('git pull');
echo $output;
geeknam / git_history.php
Created May 8, 2011 16:43
Parse git log with PHP to an array
// Author: Ngo Minh Nam
$dir = "/path/to/your/repo/";
$output = array();
exec("git log",$output);
$history = array();
foreach($output as $line){
if(strpos($line, 'commit')===0){
geeknam / .bash_profile
Created June 11, 2011 20:05
My .bash_profile
function gsup(){
gsutil cp "$@" gs://
function gsdown(){
gsutil cp gs://"$@" ~/Desktop
geeknam / .screenrc
Created June 24, 2011 03:15
Screen config
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
screen -t screen1 0
screen -t screen2 1
screen -t screen3 3