Oleg Andreev

Month
Filter by post type
All posts

Text
Photo
Quote
Link
Chat
Audio
Video
Ask

May 2009

MurmurHashmurmurhash.googlepages.com

“The name, if you’re wondering, comes from the simplest sequence of operations which will thoroughly mix the bits of a value - "x *= m; x = rotate_left(x,r);” - multiply and rotate. Repeat that about 15 times using ‘good’ values of m and r, and x will end up pseudo-randomized"

Austin Appleby.

May 27, 2009
#hash #algorithm #murmur #quote #link
“

HFS+ also has a few specific optimizations. When a file is opened on an HFS+ volume, the following conditions are tested:

— The file is less than 20 MB in size
— The file is not already busy
— The file is not read only
— The file is fragmented (the eighth extent descriptor in its extend record has a non-zero block count)
— The system uptime is at least 3 minutes

If all the above are satisfied, the file is relocated (de-fragmented) - on-the-fly.

”
—What Is Mac OS X?, Mac OS X Filesystems (Amit Singh)
May 24, 2009
#hfs #mac #paper #fs #optimization #defragmentation
The rsync algorithm tech reportsamba.org
May 24, 2009
#rsync #diff #algorithm #checksum
Play
May 23, 2009
Sorting algorithm animationssorting-algorithms.com

Thanks to gotsyk for the link.

May 22, 20091 note
#sort #algorithm #animation
The Little Manual of API Designchaos.troll.no

Thanks to julik for the link.

May 22, 20091 note
#api #design #manual #whitepaper
Human-friendly Base32 encoding by Douglas Crockfordcrockford.com

The encoding scheme is required to

— Be human readable and machine readable.
— Be compact. Humans have difficulty in manipulating long strings of arbitrary symbols.
— Be error resistant. Entering the symbols must not require keyboarding gymnastics.
— Be pronounceable. Humans should be able to accurately transmit the symbols to other humans using a telephone.

May 15, 2009
#encoding #base32 #crockford #link #quote
Recursive descent parser in JavaScript

Parser.js
JSONGrammar.js

The parser enables you to write BNF-like rules directly in JavaScript without need to compile the file (like with Ragel, YACC, Bison, ANTLR etc.)

The grammar is a JS function with 11 arguments (9 rules and 3 hooks). Each rule gets two arguments: text (string) and state (arbitrary value) and returns a tuple of new text and new state (or null if rule was not matched). Parser walks character by character from left to right. text is always a tail of the initial text. Generally, text is empty string when parser finishes.

All(rule1, rule2, …) — a sequence of rules. Example: All(Char(“[”), list, Char(“]”)) defines a JS array.

Any(rule1, rule2, …) — “OR” rule for any number of rules. Example: JSONValue = Any(StringRule, ObjectRule, ArrayRule, …)

Char(alphabet) — character matching rule. Example: digit = Char(“0123456789”)

NotChar(alphabet) — inverse of Char(). Any character — NotChar(“”).

Optional(rule) — tries to match rule and skips it if not matched. Example: optSpace = Optional(Char(“ \t\r\n”))

EOF — matches the end of the text. Fails if text != “”.

Terminator — terminates parser. That is, always returns empty text.

Y — Y-combinator for defining recursive rules. Example: X = Y(function(x) { return abc(x) } ), where x is equal to X. Google for more info on Y-combinator.

Hooks enable you to actually build some structures using your grammars. Every hook returns a new state value to use in further rules. You should avoid mutable state values because some rules may be thrown away if not matched later (remember: this is a recursive parser!). For example, use array.concat([value]) instead of array.push(value).

Capture(rule, function(buffer, state1){ return state2 }) — captures raw string buffer to store in the state2.

Before(rule, function(state1){ return state2 }) — creates a new state for the rule (e.g. creates empty array for array syntax).

After(rule, function(beforeState, afterState){ return newState }) — creates a new state after successful match. You can put nested values to the container if beforeState is a container before rule parsing, afterState is a nested value (after rule match) and newState is a new container with this value.

See usage examples in JSONGrammar.js

See the parser source code in Parser.js

May 11, 20092 notes
#parser #bnf #js #recursion
single-letter aliases for git commandsgithub.com
May 7, 2009
#git #aliases #bash #github
“

How to use Natural Order

Drop Natural Order into the System Folder and Restart your Mac.

”
—NaturalOrderSort.org
May 5, 2009
#link #sorting #algorithm #plugin #mac #quote

April 2009

Singletons are Pathological Liarsmisko.hevery.com
Apr 30, 2009
#link #singleton #lie #design #pattern
What C-integration problems arise with stackless VM implementations?stackoverflow.com
Apr 30, 2009
#question #vm #stackless #c #bindings
Jim Weirich rocks at Rubyconf 2009: talk about modularitymwrc2009.confreaks.com
Apr 29, 2009
#video #weirich
Cuckoo hashing papers

A Cool And Practical Alternative To Traditional Hash Tables

More Robust Hashing: Cuckoo Hashing with a Stash


Recent advances in the theoretical literature have proposed interesting modifications to traditional hash tables. The authors of these papers propose hash tables which

a) have a guaranteed constant time for a lookup
b) have amortized constant time for an insertion
c) require table size only slightly larger than the space for the elements

Previous hash table technologies have offered at most two of these three.

Apr 29, 2009
#hashing #cuckoo #papers
Cuckoo hashing algorithmen.wikipedia.org
Apr 29, 2009
#hashing #algorithm #cuckoo #wikipedia #science #cs
“Curious how the people obsessed with reducing extra indirections in their code are happy to waste indirections in their own minds.”—Steve Dekorte @ twitter
Apr 29, 2009
#indirections #code #design #quote
Robust singletons in AS3

This is funny.

Apr 28, 2009
#as3 #stupid #singleton #code
Apr 27, 2009
#as3 #stupid #code
"hash-table" objects vs. message-receiving objects

(Thanks to Julik for inspiring to think on the subject.)

In Io, JavaScript and Python there’s a model of “hash-table” objects. The object contains some slots, which you access and then decide what to do with them. If the slot appears to be a function, you can call it. In JS there’s a bit of magic: interpreter knows where the function just came from, so it can specify reasonable “this” pointer for function call. In Io there’s less smart decision: upon slot access interpreter checks “activatable” property of the object (not the slot entry, but the object this slot refers to!) and activates the object if it happens to be a method. However, in Io x := y is being a message setSlot(‘x’, y), so that you can hook in.

On the other hand, Ruby has a much stronger notion of message passing: you never ever can modify inner object data (that is, @ivars) without message send. The most simple @foo update happens through the accessor method called foo=.

However, from the implementation point of view, Ruby has two kinds of hash tables per object: method table and ivars table.

Apr 11, 2009
#io #ruby #python #js #hashtable #design
Implementation vs. Idea

Implementation is created under time and knowledge constraints. Therefore, it is full of bugs, and it becomes obsolete as soon as our knowledge evolves. What is important in technology: the idea and context behind each decision.

Apr 3, 20091 note
#ideas #legacy #knowledge #implementation
Io namespaces
Io namespaces are created using regular objects. However, there’s no such thing as “lexical context” In Io, so the Foo will not be able to access Bar in the following example: MyApp := Object clone do( Foo := Object clone do( bar := method(Bar) # Bar is not accessible from here! ) Bar := Object clone do( foo := method(Foo) # Foo is not accessible from here! ) ) How can we improve that? First, lets define MyApp with Module clone rather than Object clone: MyApp := Object Module clone do( Foo := Object clone do( bar := method(Bar) ) Bar := Object clone do( foo := method(Foo) ) ) All we need now is to have all inner objects to have MyApp in the list of prototypes. Therefore, lets override Object slot to refer to MyApp rather than the standard Object: Module := Object clone do( Object := method(self) ) See Module.io on GitHub.
Apr 3, 2009
#io #namespaces
Null Pattern revisited

Yesterday I have rewritten 3600 LOC codebase in ActionScript as if there were “message eating” null in the core and the standard libraries (please see A Generalized Null Object Pattern by Nevin Pratt). I got a diff with just 100 lines removed and 180 lines updated. It is at most 7% code reduction.

It seems that “message eating” null neither produces considerably more elegant code, nor considerably more brittle code (in all cases ignoring null value is correct).

In sense of VM implementation, it might be easier to implement a classical “exception raising” null and use custom Null Pattern classes where appropriate.

Apr 2, 2009

Good software framework saves much more time providing explicit knowledge where to put things in, rather then providing syntactic steaks and strippers.

Apr 2, 2009
#frameworks

March 2009

iovm idea: “activatable” should be a slot property rather than value property. This allows to pass methods around and access them directly by slot name in all the contexts. Current implementation makes you to use getSlot(slotName) syntax to avoid activation.

Mar 31, 2009
#io #slots #activation #iovm
A Generalized Null Object Patternweb.cecs.pdx.edu

Excellent write up about “message eating” Nil.

Mar 31, 2009
#null #nil #none #void #stub #smalltalk
Nil and None considered Null and Voidhomepages.mcs.vuw.ac.nz
Mar 31, 2009
#null #void #nil #none #oop #patterns #stub
“In terms of navigation, Skype’s VoIP app for iPhone looks more like your traditional iPhone app than it does Skype 4.0 for Windows. For many who already prefer Apple’s sleek interface archetype, that’s a triumph, but those who enjoy Skype’s branding may feel disappointed.”—Some stupid cunt from reviews.cnet.com compares iphone with windows
Mar 31, 2009
Andrea Martignoni street animationyoutube.com
Mar 28, 2009
#video #humor #art #youtube #animation
Button Wrap :-)antongerasimenko.com
Mar 27, 2009
#humor
Mar 26, 2009
#management #design
Math.random() and srand in AS3

There’s no “srand” function in AS3. That is you cannot seed random number generator.

And when you get the very same results each time swf is loaded you find this:

External image

However, if you need true randomness in an event-driven application, you can do this:

setInterval(Math.random, 10)

Flash Player will run Math.random() in background producing different random values at different points of time.

Mar 26, 20091 note
#as3 #random #workaround #security #screenshot
Balanced priority queue (weighted queue)

In a regular priority queue entry with priority N is taken before all the entries with priority M (given N > M).

Sometimes, however, 3-priority entry should not beat one hundred of 1-priority items. It seems natural to introduce a double-linked list of weighted nodes, where newly inserted node can come in front of a limited number of nodes with a total weight less then a weight of a new node.

Illustration. Given a stream of nodes with weights:

[1a, 2, 1b, 3, 1c, 1d, 4, 1e]

weighted queue intermediate states would be:

[1a]
[2, 1a]
[2, 1a, 1b]
[2, 3, 1a, 1b]
[2, 3, 1a, 1b, 1c]
[2, 3, 1a, 1b, 1c, 1d]
[2, 3, 1a, 4, 1b, 1c, 1d]
[2, 3, 1a, 4, 1b, 1c, 1d, 1e]

In such queue priority “N” means skipping N items of priority 1.

Mar 17, 20091 note
#queue #algorithms #math
WhatTheFont: helps to find a name for the font using image recognitionnew.myfonts.com
Mar 16, 2009
#fonts #image recognition #ai
refuckflash.rb: reclone working directory to refresh Flash CS3 classpath buggist.github.com
Mar 13, 2009
#gist #code #git #refuck #flash #classpath #snippet #script #util
Let your mom double click buttons safely (AS3 snippet) gist.github.com
Mar 11, 2009
#as3 #ui #actionscript #click #gist #code
The simplest and the most beautiful state machine implementation in AS3gist.github.com
Mar 11, 2009
#actionscript #as3 #state machine #code
Evening, easy listening

Observation: office becomes nicer when everybody leaves :-)

Mar 9, 2009
#observations #office #evening #actionscript
“
// I dedicate all this code, all my work, to my wife, Darlene, who will 
// have to support me and our three children and the dog once it gets 
// released into the public.
”
—Stack Overflow: What is the best comment in source code you have ever encountered?
Mar 6, 2009
#code #humor #stackoverflow #<>
Creating dangling branches in Git

Say, you want to keep some auxiliary info inside your git repository: tickets, post-commit/post-receive hooks, wiki pages etc. Storing them inside a folder might not be a good idea: you’d probably want to have same content across all the branches. It is natural to keep such data in a separate branch.

Given that, you can create your “tickets” branch simply by checking out new branch, removing all the code, adding initial files and committing it. This works great until you get bored with the irrelevant history in the tail of the git-log. It is rather easy to disconnect your branch from the old history: just take the latest tree id, create an orphan commit (that is: without parent commits) and reset branch to this commit.

# emit tree id for the latest commit
$ git log -1 --pretty=format:%T

# emit new commit id
$ echo "initial commit" | git commit-tree <tree-id>

# reset current branch to this commit id
$ git reset --hard <commit-id>


Put it in a single bash command:

$ git reset --hard `echo "initial commit" | git commit-tree \`git log -1 --pretty=format:%T\``

Dangling branches are great for keeping meta-data of any sort: .git/config files, tickets, hooks, documentation, tickets.


PS. Since you can store hooks inside repository itself, you can have a self-contained deployment system like Capistrano without any additional tools installed on a server. Hooks can even update themselves on each post-receive hook before actual deployment recipes are run. This allows you to specify all the dependencies in the source repository and even setup them with a single “git push” command. All manual setup you have to do initially is to clone local repository inside .git/hooks folder (yes, inside itself) and check out hooks branch appropriate for your environment. Ain’t that sweet?

Mar 4, 20092 notes
#git #advanced #branches #dangling #deploy #capistrano
TraceMonkey analysis and visualizationblog.mozilla.com

Nice article showing efficiency and inefficiency of TraceMonkey. Must read.

Mar 1, 2009
#tracemonkey #js #vm #optimization #visualization #graphs
2x performance increase using denormalized MySQL storagebret.appspot.com

FriendFeed stores all entities with all properties in a single table and uses separate tables for specific indexes. After retrieving entities from the index, application reapplies query to fight some data inconsistencies. Eventually, “cleaner” process updates indexes with the actual data. This strategy greatly reduces administration efforts (indexes can be created or update asynchronously) and makes latency 2x lower.
(Thanks Application Error for the link)

Mar 1, 2009
#mysql #schemaless #db #latency #experience #performance

February 2009

man git-commit-tree
DIAGNOSTICS
       You don't exist. Go away!
           The passwd(5) gecos field couldn't be read

       Your parents must have hated you!
           The passwd(5) gecos field is longer than a giant static buffer.

       Your sysadmin must hate you!
           The passwd(5) name field is longer than a giant static buffer.
Feb 25, 2009
#git #humor #fun #man #diagnostics #errors
ruby inject mastery
def movie_events_grouped_by_titles_and_theaters
   events = Event.all.inject({}) do |titles, event|
     ((titles[event.title] ||= {})[event.theater] ||= []) << event
     titles
   end
end 
(my response to the mail list discussion; in russian)
Feb 24, 2009
#ruby #inject #snippet
~/.gitconfig
[user]
    name = Oleg Andreev
    email = oleganza@gmail.com

[apply]
    whitespace = strip

[diff]
    color = auto
    rename = copy

[pager]
    color = true

# this one is very cool: 
#   green means "to be committed" 
#   red means "not to be committed"
[status]
    color = auto
Feb 24, 2009
#git #gitconfig
Github storygist.github.com

Must read.

Feb 20, 2009
#git #github #story #keynote #gist #success #failure #reading
GitHub is a social network, indeed

Today I have received a letter:

Hello Oleg,

I’m a Io newbie. I was watching some of your sample code on Github (loved funnyFactorial ;-) when I discovered your “learning french” subdir. I’m french and would be pleased to answer / comment / whatever about that language (not so human).

^_^
Feb 18, 2009
#github #french #social #help #curiosity #learning #git #io #email
Unpublished MySQL FAQsqlanywhere.blogspot.com
Feb 18, 2009
#humor #sql #mysql #faq #blog #db #stupid
Github pagesgithub.com

Github offers you a HTTP server for static data at http://yourname.github.com. Publishing is easy: just push content to git@yourname.github.com. (It is two months already, how could I miss!)

Feb 17, 2009
#github #git #pages
Git cookbook: commit id for a given path
$ git rev-list -n 1 HEAD <path/to/folder>

Returns the latest commit, which modified a given path. This is useful to find out whether something has recently changed in the particular folder.

Feb 17, 2009
#git #howto
Time-driven development

Young hacker looks at the figures: “2 hours for the feature Foo, 4 hours for the feature Bar”. He feels that kind of pressure: “I have to make it! I have to type faster, think faster, test faster.”

This is an awful feeling. So here’s the (possible) solution to this situation: try to think of time as of money you are investing. Tell yourself how much time of your life would you invest into this piece of #$@^ (of course, take into account your rate/salary). Now it looks like you score the feature Foo for just 2 hours: it doesn’t worth 4 hours or more. Spend 10-15 minutes for planning the way to spend that much time and do your best. If some trouble strikes and you’re out of time, just give up. Go to another feature and let this to be discussed on a weekly meeting when there’s time to schedule next iteration.

If the client wants a fixed price for software, you will not have any additional time. In such case - either do a dirty job, or work all the night. You to decide.

Feb 16, 20091 note
#time #planning #tdd
Next page →
20152016
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
201420152016
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
201320142015
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
201220132014
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
201120122013
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
201020112012
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200920102011
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200820092010
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200720082009
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200620072008
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200520062007
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200420052006
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200320042005
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200220032004
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200120022003
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
200020012002
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199920002001
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199819992000
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199719981999
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199619971998
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199519961997
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199419951996
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199319941995
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199219931994
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199119921993
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
199019911992
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
198919901991
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
198819891990
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
198719881989
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
198619871988
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
19861987
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December