This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lambda | |
#lambda parameter: expression | |
f = lambda x, y: x + y | |
f(15,1) | |
#=> 16 | |
#using within a high order function | |
def my_function(x): | |
return lambda arr: [x * each for each in arr] | |
fives = my_function(5) | |
print fives([1,2,3,4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factory(x): | |
def multiply(my_array): | |
my_array2 = [] | |
for each in my_array: | |
my_array2.append(each*x) | |
return my_array2 | |
return multiply | |
#using lambda | |
def factory(x): | |
return lambda arr: [x * el for el in arr] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f1(seq): | |
# not order preserving | |
set = {} | |
map(set.__setitem__, seq, []) | |
return set.keys() | |
def f2(seq): | |
# order preserving | |
checked = [] | |
for e in seq: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def table_things(**kwargs): | |
... for name, value in kwargs.items(): | |
... print '{0} = {1}'.format(name, value) | |
... | |
>>> table_things(apple = 'fruit', cabbage = 'vegetable') | |
cabbage = vegetable | |
apple = fruit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def print_everything(*args): | |
for count, thing in enumerate(args): | |
... print '{0}. {1}'.format(count, thing) | |
... | |
>>> print_everything('apple', 'banana', 'cabbage') | |
0. apple | |
1. banana | |
2. cabbage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> <label>TestDynamicPanel</label> <fieldset submitButton="false"> <input type="dropdown" token="show1"> <label>Dropdown1</label> <populatingSearch fieldForLabel="temp" fieldForValue="temp">|gentimes start=-1 | eval temp="ColumnChart" | table temp</populatingSearch> </input> <input type="dropdown" token="show2"> <label>Dropdown2</label> <populatingSearch fieldForLabel="temp" fieldForValue="temp">|gentimes start=-1 | eval temp="LineChart" | table temp</populatingSearch> </input> <input type="dropdown" token="show3"> <label>Dropdown3</label> <populatingSearch fieldForLabel="temp" fieldForValue="temp">|gentimes start=-1 | eval temp="Table" | table temp</populatingSearch> </input> </fieldset> <row> <panel> <chart depends="$show1$"> <title>Details for $submitted:sourcetype|s$</title> <searchString>index=_internal | timechart count</searchString> <earliestTime>-15m</earliestTime> <latestTime>now</latestTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mechanize | |
br = mechanize.Browser() | |
br.add_password("http://blah.blah/", "adm", "mps") | |
response = br.open("http://blah.blah/somepage.html") | |
br.select_form(nr=1) | |
br["junk"]=["hatethis"] | |
response3=br.form.click(name="applybutton",nr=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import cPickle as pickle | |
def cached_data(): | |
cache_path = "/tmp/cached-data.pickle" | |
if not os.path.exists(cache_path): | |
# The cache doesn't exist, create it and populate it | |
result = generate_data() | |
cache_file = open(cache_path,'wb') | |
# Write it to the result to the file as a pickled object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# I wasn't happy with any of the GitHub libraries for Python that I tried so I | |
# just used the GitHub API directly. If someone would like to rewrite this | |
# using a library please be my guest | |
import argparse | |
import base64 | |
import getpass | |
import json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import json | |
# Authentication details. To obtain these visit dev.twitter.com | |
consumer_key = '' | |
consumer_secret = '' | |
access_token = '' | |
access_token_secret = '' | |
# This is the listener, resposible for receiving data |
NewerOlder