Skip to content

Instantly share code, notes, and snippets.

@hollastic
hollastic / gist:4708165
Created February 4, 2013 17:29
jQuery: Traversing methods
jQuery Traversing Methods
#########################
Three types:
1) Filtering
------------
.eq()
.filter()
@hollastic
hollastic / gist:4708115
Created February 4, 2013 17:19
jQuery: chaining methods
// The code sample below uses both the .not() method and the .parent() method.
// Combined together this will only select the parent elements of div elements
// without a class of type or collection.
$('div').not('.type, .collection').parent();
@hollastic
hollastic / gist:4708092
Created February 4, 2013 17:16
jQuery: Traversing using filter (.not)
// In the example below the original selection finds all of the div elements in the DOM,
// which are then filtered using the .not() method. With this specific method all of the
// div elements without a class of type or collection will be selected.
$('div').not('.type, .collection');
@hollastic
hollastic / gist:4708064
Created February 4, 2013 17:12
jQuery: This selection keyword
// When working inside of a jQuery function you may want to select the element in which was referenced
// inside of the original selector. In this event the this keyword may be used to refer to the element
// selected in the current handler.
$('div').click(function(event){
$(this);
});
@hollastic
hollastic / gist:4708046
Created February 4, 2013 17:08
jQuery: type of selectors
$('.feature'); // Class selector
$('li strong'); // Descendant selector
$('em, i'); // Multiple selector
$('a[target="_blank"]'); // Attribute selector
$('p:nth-child(2)'); // Pseudo-class selector
@hollastic
hollastic / gist:4708035
Created February 4, 2013 17:07
jQuery: document ready
$(document).ready(function(event){
// jQuery code
});
@hollastic
hollastic / tipsandtricks.py
Created February 4, 2013 11:41
Python: tips and tricks
# PYTHON TIPS AND TRICKS FROM Alexis Métaireau
# http://alexis.notmyidea.org/pythontricks/
import string
from collections import namedtuple
from collections import Counter
# STRINGS
print 'hackers gonna hack'. partition(' ') # partition the first space
@hollastic
hollastic / runall.py
Created January 29, 2013 09:17 — forked from antlypls/runall.py
Python: runall files in a dir
import os
path = os.getcwd()
for root, dirs, files in os.walk(path):
print("visiting: ", root)
os.chdir(root)
py_files = [file for file in files if file[-3:]=='.py']
for py_file in py_files:
cmd = "python {0}".format(py_file)
print("running: ", cmd)
@hollastic
hollastic / .py
Created January 29, 2013 09:13 — forked from 0xnbk/.py
Python: twitter follower filter
import twitter, sys, getpass, os
def call_api(username,password):
api = twitter.Api(username,password)
friends = api.GetFriends()
followers = api.GetFollowers()
heathens = filter(lambda x: x not in followers,friends)
print "There are %i people you follow who do not follow you:" % len(heathens)
for heathen in heathens:
print heathen.screen_name