This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import socket | |
HOST="irc.freenode.net" | |
PORT=6667 | |
BOTNAME="sweemengs_bot" | |
CHANNEL="#myoss" | |
class Bot(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python/ | |
# Get xively library in https://github.com/xively/xively-python | |
import xively | |
import datetime | |
def main(): | |
now = datetime.datetime.utcnow() | |
earliest = now - datetime.timedelta(minutes=30) | |
api = xively.XivelyAPIClient("SL2N1SZTVFZHxb2p2DXq1GdtaKInCpv521mFtOxwmkrrBvsL") | |
feed = api.feeds.get("1068165020") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import twitter | |
import pydot | |
api = twitter.Api(username='usename',password='password') | |
g=pydot.Dot(graph_type='graph',font='verdana',overlap='false') | |
[g.add_edge(pydot.Edge('username',i.name)) for i in api.GetFriends()] | |
g.write_svg('socialnet.svg',prog='neato') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/awk -f | |
#will fail with several case, still investigating | |
BEGIN{ | |
print "begin"; | |
} | |
{ | |
count=0; | |
for(f=1;f<=NF;f++){ | |
if($f==""){ | |
if(count==0){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Don't Do This, it will cause a runtime error, | |
d = {"a":1,"b":2,"c":3} | |
for i in d: | |
del d[i] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from haystack.forms import SearchForm | |
from django import forms | |
from haystack.query import SearchQuerySet | |
SEARCH_FILTER =[('all','all'),('name','name'),('business','sector'),('address','address')] | |
class FilterSearchForm(SearchForm): | |
def __init__(self,*args,**kwargs): | |
super(FilterSearchForm,self).__init__(*args,**kwargs) | |
self.fields['keys'] = forms.ChoiceField(choices=SEARCH_FILTER,required=True, | |
label='search in') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls.defaults import * | |
from views import * | |
from haystack.views import SearchView | |
from haystack.forms import SearchForm | |
from forms import FilterSearchForm | |
urlpatterns = patterns('', | |
(r'^$',SearchView(form_class=FilterSearchForm, | |
load_all=False)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import urllib2 | |
# here i use json, but the api also support xml | |
import json | |
# for url parameter, just to make it look nice | |
param = urllib.urlencode({'api':'your api key','format':'json'}) | |
# get population of malaysia | |
url = 'http://open.worldbank.org/countries/my/indicators/SP.POP.TOTL' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from os.path import abspath,dirname | |
THIS_DIR = dirname(__file__) | |
TEMPLATE_DIRS = ( | |
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". | |
# Always use forward slashes, even on Windows. | |
# Don't forget to use absolute paths, not relative paths. | |
abspath(THIS_DIR+"/../template") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls.defaults import * | |
# Uncomment the next two lines to enable the admin: | |
from django.contrib import admin | |
admin.autodiscover() | |
urlpatterns = patterns('', | |
# Example: | |
# (r'^project/', include('project.foo.urls')), |
OlderNewer