Skip to content

Instantly share code, notes, and snippets.

@papachan
papachan / helloworld.js
Created October 11, 2011 17:51
helloworld.js
var http = require('http');
var server = http.createServer(function(req,res){
res.writeHead(200, {'Content-type': 'text/plain'})
res.end("hello world\n");
});
@papachan
papachan / python-openurl.py
Created October 30, 2011 14:31
python download url and save it to your compputer from a txt file
import os
import os.path
import time
import urllib2
import codecs
# python download url and save it to your compputer from a txt file
dirname = "/Users/papachan/Desktop/site/static/"
filename = "url.txt"
import MySQLdb
if __name__ == "__main__":
db = MySQLdb.Connect(host="localhost", user="user",passwd="",db="mysqldbname")
cursor = db.cursor()
cursor.execute("SHOW ENGINES")
for row in cursor.fetchall():
print row
import MySQLdb
sql = """INSERT INTO table ( value_1 , created_at , value_2 , text ) VALUES (%s,%s,%s,%s,%s)"""
if __name__ == "__main__":
db = MySQLdb.Connect(host="127.0.0.1", user="admin",passwd="",db="mysql_dbname")
c = db.cursor()
try :
c.execute(sql, ('value', '0000-00-00 00:00:00', 'value 2', 'my etxt'))
db.commit()
@papachan
papachan / mysql.py
Created July 2, 2012 22:22
eliminate duplicate rows in table
import MySQLdb
def main(first):
sql = """SELECT * FROM `articles_autores`
ORDER BY article_id ASC
LIMIT %s"""
sql3 = """DELETE FROM `articles_autores` WHERE articles_autores.id = %s;"""
db = MySQLdb.connect(host='localhost', user='user',passwd='',db='test_duplicate');
cursor = db.cursor()
cursor.execute(sql % first)
#!/usr/bin/env python
import sys
import re
import subprocess
av = list(sys.argv)
av[0] = "ant"
p = subprocess.Popen(av, stdout = subprocess.PIPE)
try:
import time, subprocess, os, sys, platform
except Exception as e:
sys.stderr.write(str(e))
exit(84)
def log_msg(msg):
log=open("log","a")
log.write(str(msg)+"\n")
log.close()
V/python ( 3896): Extracting public assets.
D/dalvikvm( 3896): GC_FOR_ALLOC freed 1266K, 21% free 9353K/11719K, paused 12ms
I/dalvikvm-heap( 3896): Grow heap (frag case) to 10.194MB for 1048592-byte allocation
D/dalvikvm( 3896): GC_FOR_ALLOC freed 1K, 12% free 10375K/11719K, paused 13ms
I/python ( 3896): extracting background.png
E/python ( 3896): could not open /mnt/sdcard/org.kivy.sshshell/background.png
D/TextLayoutCache( 3896): Using debug level: 0 - Debug Enabled: 0
D/dalvikvm( 3896): GC_CONCURRENT freed 26K, 12% free 10388K/11719K, paused 3ms+3ms
W/python ( 3896): java.io.IOException: open failed: EACCES (Permission denied)
W/python ( 3896): at java.io.File.createNewFile(File.java:940)
import kivy
kivy.require('1.5.0')
import kivy.core.window
from kivy.config import Config
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class MainUI(FloatLayout):
pass
var express = require('express'),
path = require('path'),
http = require('http'),
redis = require('redis'),
path = require('path'),
url = require('url');
function contains(arr,obj) {
return (arr.indexOf(obj) != -1);
}