Skip to content

Instantly share code, notes, and snippets.

View geeknam's full-sized avatar

Nam Ngo geeknam

View GitHub Profile
@geeknam
geeknam / xmppemail.py
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]
logging.debug(user)
@geeknam
geeknam / gae_webservice.py
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
geeknam / getpic.js
Created January 13, 2011 15:17
Chrome Extension to get RP pics
function showPic(){
$("#studentImage").hide().html(getPic()).fadeIn(2000);
$("#studentId").val("");
$("#fullname").val("");
}
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
geeknam / rpavatar.html
Created January 13, 2011 15:19
HTML skeleton of Chrome Extension
<html>
<head>
<link type="text/css" href="style.css" rel="stylesheet" />
<script src="jquery.js"></script>
<script src="getpic.js"></script>
</head>
<body>
<div id="header">
<a href="http://myrp.sg/sass-student/" target="_blank">Login here</a>
before using this extension
site = SitesApp.getSite("myrp.edu.sg", "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
geeknam / internet_sharing.scpt
Created March 5, 2011 18:36
Applescript to activate Internet Sharing
register_growl()
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 "com.apple.preferences.sharing"
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
geeknam / git-pull-all.php
Created April 16, 2011 17:20
Executes 'git pull' in all directories
<?php
/* Author: Ngo Minh Nam */
$dirs = array_filter(glob(dirname(__FILE__)."/*"), 'is_dir');
print_r($dirs);
foreach($dirs as $dir){
chdir($dir);
$output = shell_exec('git pull');
echo $output;
}
@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 / .bash_profile
Created June 11, 2011 20:05
My .bash_profile
function gsup(){
gsutil cp "$@" gs://geeknam.info
}
function gsdown(){
gsutil cp gs://geeknam.info/"$@" ~/Desktop
}
@geeknam
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