Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
(ns monad-explore.core | |
(:use clojure.algo.monads)) | |
(defmacro let? | |
"Almost the same as let. If you add the :ensure keyword paired with | |
some predicate as a var in the let form, let? will not continue | |
unless the predicate evaluates to true. (The predicate will have | |
access to all bindings above.)" | |
[bindings & body] | |
(let [[bind [kwd pred & more]] (split-with (complement #{:ensure}) bindings)] |
(defmacro defconst [const-name const-val] | |
`(def | |
~(with-meta const-name | |
(assoc (meta const-name) :const true)) | |
~const-val)) | |
(defmacro defconsts [bindings] | |
`(do | |
~@(map (fn [[const-name const-val]] | |
`(defconst ~const-name ~const-val)) |
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 |
$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) | |
... |
#!/usr/bin/env stack | |
-- stack --resolver lts-3.11 --install-ghc runghc --package array --package containers | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as B | |
import qualified Data.IntMap.Strict as IM | |
import qualified Data.Map.Strict as M | |
import qualified Data.Sequence as Seq | |
import Data.Sequence ((<|), (><)) |
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 | |