Skip to content

Instantly share code, notes, and snippets.

@sweemeng
sweemeng / ircbot.py
Created February 26, 2014 13:46
Beginning of a IRC bot
#!/usr/bin/python
import socket
HOST="irc.freenode.net"
PORT=6667
BOTNAME="sweemengs_bot"
CHANNEL="#myoss"
class Bot(object):
@sweemeng
sweemeng / reader.py
Created March 20, 2014 13:07
Xively demo with tgs2600
#!/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")
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')
@sweemeng
sweemeng / emptyfield.awk
Created January 4, 2010 02:32
a awk script to print the field number with empty line
#!/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){
#Don't Do This, it will cause a runtime error,
d = {"a":1,"b":2,"c":3}
for i in d:
del d[i]
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')
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)),
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'
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")
)
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')),