Skip to content

Instantly share code, notes, and snippets.

# print a user's tweets
import simplejson
import re
import urllib2
import string
me = urllib2.urlopen('http://twitter.com/statuses/user_timeline/peteskomoroch.json?count=200')
for tweet in simplejson.loads(me.read()):
print tweet['text'].encode('utf-8')
# poll a search term every 60 seconds and print tweets out
import time
import simplejson
import re
import urllib2
import urllib
last_id = False
while True:
@criccomini
criccomini / gist:3773117
Created September 23, 2012 21:33
Blackberry Storm GPS
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;
@criccomini
criccomini / gist:3773323
Created September 23, 2012 22:47
BlackBerry Peristent Store
import net.rim.device.api.crypto.SHA1Digest;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.CodeSigningKey;
import net.rim.device.api.system.ControlledAccess;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiEngine;
@criccomini
criccomini / gist:3773331
Created September 23, 2012 22:49
BlackBerry GPS
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;
public class LocationTracker extends TimerTask {
@criccomini
criccomini / gist:3773338
Created September 23, 2012 22:52
BlackBerry HTTP Client
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
public class HTTPClient {
public static String getPage(String url) {
String response = "";
try {
@criccomini
criccomini / gist:3773348
Created September 23, 2012 22:57
Hadoop, Pig, and SQL (SELECT)
SELECT * FROM mytable;
DUMP mytable;
SELECT col1, col2 FROM mytable;
mytable = FOREACH mytable GENERATE col1, col2;
DUMP mytable;
SELECT col1 AS new_col1, col2 AS new_col2 FROM mytable;
mytable = FOREACH mytable GENERATE col1 AS new_col1, col2 AS new_col2;
@criccomini
criccomini / gist:3773349
Created September 23, 2012 22:57
Hadoop, Pig, and SQL (JOIN)
SELECT * FROM mytable INNER JOIN othertable ON mytable.col1 = othertable.col1;
mytable = JOIN mytable BY col1, othertable BY col1;
DUMP mytable;
SELECT * FROM mytable LEFT OUTER JOIN othertable ON mytable.col1 = othertable.col1;
mytable = JOIN mytable BY col1 LEFT OUTER, othertable BY col1;
DUMP mytable;
SELECT * FROM mytable RIGHT OUTER JOIN othertable ON mytable.col1 = othertable.col1;
@criccomini
criccomini / gist:3773351
Created September 23, 2012 22:58
Hadoop, Pig, and SQL (GROUP BY)
SELECT COUNT(*) FROM mytable;
mytable = GROUP mytable ALL;
mytable = FOREACH mytable GENERATE COUNT(mytable);
DUMP mytable;
SELECT COUNT(DISTINCT col1) FROM mytable;
mytable = FOREACH mytable GENERATE col1;
mytable = DISTINCT col1;
mytable = GROUP mytable BY col1;
@criccomini
criccomini / gist:3773353
Created September 23, 2012 22:58
Hadoop, Pig, and SQL (TABLES)
CREATE TABLE newtable AS SELECT * FROM mytable;
STORE mytable INTO '/some_hdfs_folder/newtable' USING PigStorage(',');
DROP TABLE newtable;
RMF /some_hdfs_folder/newtable;