Skip to content

Instantly share code, notes, and snippets.

@taboularasa
taboularasa / wordFrequency.py
Created March 8, 2009 05:12
Word frequency with Python
# word frequency in a text
# tested with Python24 vegaseat 25aug2005
# Chinese wisdom ...
str1 = """Man who run in front of car, get tired.
Man who run behind car, get exhausted."""
print "Original string:"
print str1
print
@taboularasa
taboularasa / jQueryKeypressNav.js
Created March 9, 2009 01:43
Key Press Navigation with jQuery
$(document).ready(function()
{
// hides all DIVs with the CLASS container
// and displays the one with the ID 'home' only
$(".container").css("display","none");
$("#home").css("display","block");
// makes the navigation work after all containers have bee hidden
showViaLink($("ul#navigation li a"));
@taboularasa
taboularasa / jQueryJSON.js
Created March 9, 2009 01:53
jQuery JSON RPC
$(document).ready(function(){
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#images");
if ( i == 3 ) return false;
});
});
});
http://search.twitter.com/search.json?q=%40human_bot
{
"results": [{
"text": "@human_bot Are you feeling okay? Sounds like you've been smoking some crack with the way you've been talking lately.",
"to_user_id": 5740619,
"to_user": "human_bot",
"from_user": "taboularasa",
"id": 1306533155,
> results = []
> for app in apps:
> results.append({"appname" : app.appname})
just a small tip.. you can write this as
results = [ {"appname": app.appname} for app in apps ]
class SendTweet(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
tweet = cgi.escape(self.request.get('content')) + "duhhh"
username = "username"
login = username
password = "password"
payload= {'status' : tweet, 'source' : "GAE script"}
payload= urllib.urlencode(payload)
base64string = base64.encodestring('%s:%s' % (login, password))[:-1]
@taboularasa
taboularasa / stripSpacesFromString.py
Created March 10, 2009 21:12
take out spaces inside of a string
>>> import re
>>> myString = "apple+ monkey+ bird+ cat+"
>>> myString = re.sub("\s+", "", myString)
>>> myString = myString.rstrip('+')
>>> print myString
apple+monkey+bird+cat
<script type=”text/javascript” src=”jquery-latest.pack.js”></script>
<script type=”text/javascript” src=”jquery.highlightFade.js”></script>
function addFormField() {
var id = document.getElementById(”id”).value;
$(”#divTxt”).append(”<p id=’row” + id + “‘><label for=’txt” + id + “‘>Field ” + id + ” <input type=’text’ size=’20′ name=’txt[]‘ id=’txt” + id + “‘> <a href=’#’ onClick=’removeFormField(\”#row” + id + “\”); return false;’>Remove</a><p>”);
$(’#row’ + id).highlightFade({
speed:1000
});
@taboularasa
taboularasa / unique_list.py
Created March 18, 2009 02:54
make sure that a list has no duplicate entries
mylist = list(set(mylist))
@taboularasa
taboularasa / Erode.java
Created March 23, 2009 01:40
Open the last saved jpeg image Save it as a new jpeg image with slightly more compression Repeat 600 times
import com.sun.image.codec.jpeg.*;
PImage img;
int numberOfFrames = 600;
void setup()
{
size(1024,768);
}