Skip to content

Instantly share code, notes, and snippets.

import contract as c
import datetime
date_tuple = c.Dict(year=c.Int, month=c.Int, day=c.Int) >> (lambda d: datetime.datetime(**d))
task = c.Dict({
'key': c.String(),
c.Key('timestamp', optional=True): date_tuple,
})
CONTACT = c.Or(
c.String(regex=r'(?P<first_name>^\S+)\s*(?P<last_name>.*\S)\s*<(?P<email>.+@.+.[^.]+)>') >>
(lambda match: match.groupdict()),
c.String(regex=r'(?P<email>.+@.+..+)') >>
(lambda match: {'first_name': 'none', 'second_name': 'none', 'email': match.group()})
)
@Deepwalker
Deepwalker / gist:1685777
Created January 26, 2012 23:19
py3 metaclass hack
def py3metafix(cls):
if not py3:
return cls
else:
newcls = cls.__metaclass__(cls.__name__, (cls,), {})
newcls.__doc__ = cls.__doc__
return newcls
"""
So, you have some structure from wild. Say this will be some JSON over API.
But you cant change this JSON structure.
"""
sample_data = {
'userNameFirst': 'Adam',
'userNameSecond': 'Smith',
'userPassword': 'supersecretpassword',
'userEmail': 'adam@smith.math.edu',
'userRoles': 'teacher, worker, admin',
@Deepwalker
Deepwalker / gist:4286583
Created December 14, 2012 16:13 — forked from anonymous/gist:4286580
типа rabl
module AngryData
class Attribute
def initialize(name, options = {}, &blk)
@name = name
@options = options
@blk = blk
end
def name
@name.to_s
require 'macaddr'
module AngryUID
# TODO Now we dont resolve time problems - if
# we move time to past, then bad things can happen
class UID
CLOCK_MULTIPLIER = 10_000_000 # 10ns
# Arrange
# -------
set nocompatible " We're running Vim, not Vi!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'scrooloose/nerdtree.git'
Bundle 'vim-ruby/vim-ruby.git'
Bundle 'scrooloose/syntastic.git'
Bundle 'rodjek/vim-puppet'
Bundle 'vim-scripts/VimClojure.git'
Bundle 'vim-scripts/vim-coffee-script.git'
@Deepwalker
Deepwalker / clform.js
Created February 1, 2014 16:43
Angular directives with support for forms with nested attributes
/*
clForm and clFormInput working together.
With clForm you define context and with clFormInput
you customize simple form controls.
clForm could be nested.
Sample:
<form cl-form="package as packageForm" cl-form-prefix="delivery[legs_attributes][0][package_attributes]">
<input cl-form-input="system_of_measurement" ng-model="package.system_of_measurement">
@Deepwalker
Deepwalker / gist:9216254
Last active August 29, 2015 13:56
Sometimes you need preload associations, not join, separate load. And with this method you can preload on arrays too!
class ApplicationController < ActiionController::Base
def preload_associations(*associations)
collection = get_collection_ivar
associations.each do |association|
ActiveRecord::Associations::Preloader.new(collection, association).run
end
set_collection_ivar collection
collection
end
end
langs = %w{bfkegkudem kfpozexksm owfmkcnyvl rahgdgzhwv bukisteksg fxjeegggdx qejjzctbti qvigekhpog bvsqmvedya ewrgfpfrlu
bzvuzuanzo zhxcmwkizu ohxyodxkyv oomrfibhfw fzegixttqa kxdzqivfhl hniomtqdqr apphyuifwj ujfcrapeyx djgrcxqrux
rvtvpxbnzx bziseafhdp mofuvdculv nffrquughc gwrrvndjur mvzqilbvpi mpptidaosr lfgaxqtduu ldyzyofyar xtgkueabdj
wqhmxhcasa yxeoufxrry sphdgsweik hhunpqjpnz fnkkbvirll ncdmbrcvqi hctoategou mqtdyycvun afncjfmngf wjxyvhcsuz
puefxeidio nyfllolsvw ghjygztrnv folnzvecis uvtannbdjx jurkwqiavv wmfpexcqch ugmptanwdn eslmaaefez jxqcpsvvwu
fellmtwzsw nixzgduncg vupbjbdqke olbdbzufhe pxygpqdwoi jkhjwnpvqz ywludqlmlw kqulfxgqiv wvujqpjjwt wkmwuyazjo
mqkqtwbzxv dfeleuxjlt rgoobzxbfr pyykqgaoid qcwdcogibq kwospdrebi fbyhvdjrey uakluudovp eglxbpqtkj nxqpeffrvb
rlehisdiuy rhhexyshob flpxyqcjcy indkhpjugw qaoclhadbf ctfhonsqll mvehaiypoq joegipqmds qsblkvrxky abmhqmwnxy
zduqzarnxr nuygfvuzge qapxbfzggm yhpeuenslm huknmeiolq noxfaqgmms qovhnrrkju kdvrccwzeh jsvdszywda ldqejpsnsk
bqhdoixppa pqpckcqthi r