Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
########################################################## | |
# How to properly use Python. An efficient and yet educa-# | |
# tonal guide to the proper use of the lambda constru- # | |
# ct in Python 2.x. [DO USE THIS AT ALL TIMES] # | |
# by: e000 (13/6/11) # | |
########################################################## | |
## Part 1. Basic LAMBDA Introduction ## | |
# Well, it's worth diving straight into what lambdas are. | |
# Lambdas are pretty much anonymous "one line" functions |
user_agents = [ | |
(30.7, '''Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;) | |
Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) | |
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB5; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0) | |
Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1; .NET CLR 3.0.04506.30) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727) | |
Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC) | |
Mozilla/2.0 (compatible; MSIE 4.0; Windows 98) | |
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) | |
Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC) |
-- creates a class table which has a "new" method to create object instances. | |
class = function (parentclass, classdef) | |
local cls = { | |
__classdef__ = classdef or {}, | |
__parent__ = parentclass or {}, | |
-- instance constructor | |
new = function(cls, ...) | |
local instance = { | |
super = cls.__parent__.__classdef__, |
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 | |
Type "copyright", "credits" or "license()" for more information. | |
>>> import random | |
>>> random.seed() | |
>>> import nltk | |
>>> from nltk.corpus import wordnet as wn | |
>>> nouns, verbs, adjectives, adverbs = [list(wn.all_synsets(pos=POS)) for POS in [wn.NOUN, wn.VERB, wn.ADJ, wn.ADV]] | |
>>> def gen_phrase(*pattern): return [random.choice(i) for i in pattern] |
$snapins = Get-PSSnapin -Registered | |
$snapins | Add-PSSnapin | |
Get-Module -ListAvailable | Import-Module | |
Get-PSSnapin | Format-Table -autosize PSVersion, Name | |
Get-Module | Format-Table -autosize ModuleType, Name | |
function ff ([string] $glob) { get-childitem -recurse -include $glob } |
One of my favorite past times is to look at the notebooks of famous scientists. Da Vinci's notebook is well known, but there plenty others. Worshipping Da Vinci like no other, I bought a Think/Create/Record journal, used it mostly to keep jot down random thoughts and take notes. This was great in the beginning, but the conformity of lines drove me nuts. Only moleskines made blank notebooks, so I had to buy one.
At the same time I started a freelance project. The project itself is irrelevant, but suffice to say it was very complex and spanned several months. It seemed like a perfect opportunity to use the moleskine. Looking back, all my entries fell under few categories:
def enum_class(cls): | |
"""Decorates a class to set it's attributes to values of their | |
literal names. This is cool to use to make an 'enum' class and | |
have PyCharm also infer it's members. | |
Use it like so: | |
>>> @enum_class | |
... class KindOfFruit: | |
... Apple, Orange, Banana, Passionfruit = range(4) | |
... |
type SomethingViewModel() as this = | |
inherit ViewModelBase() | |
let (<<+) (_ : unit) (e : Microsoft.FSharp.Quotations.Expr) = | |
this.OnPropertyChanged e | |
let mutable somePropertyValue = "" | |
member x.SomeProperty | |
with get() = somePropertyValue | |
and set value = (somePropertyValue <- value) <<+ <@ x.SomeProperty @> |
// This operator is used in the slides for this talk: http://fwaris.wordpress.com/2013/01/31/unraveling-the-mystery-of-monads/ | |
// I haven't seen all the slides yet but I took a shot on implementing it myself. | |
let (<||>) a b = async { | |
let! a = Async.StartChild a | |
let! b = Async.StartChild b | |
let! ar = a | |
let! br = b | |