Skip to content

Instantly share code, notes, and snippets.

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'
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'citizenwatch.db' # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
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.db import models
# Create your models here.
ISSUE_TYPE = (
('Broken Streetlight','Broken Streetlight'),
('Pipe Leakage','Pipe Leakage'),
('Pot Hole','Pot Hole'),
('alien infestation','alien infestation'),
('stray dogs','stray dogs'),
('runaway velociraptor','runaways velociraptor')
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'issue'
)