Oleg Andreev

Month
Filter by post type
All posts

Text
Photo
Quote
Link
Chat
Audio
Video
Ask

June 2009

“Virtually all commercial applications in the 1960’s were based on files of fixed-length records of multiple fields, which were selected and merged. Codd’s relational theory dressed up these concepts with the trappings of mathematics (wow, we lowly Cobol programmers are now mathematicians!) by calling files relations, records rows, fields domains, and merges joins. To a close approximation, established data processing practise became database theory by simply renaming all of the concepts.”—Henry G. Baker to ACM forum
Jun 30, 2009
#db #relational databases #acm #dekorte
A problem with stackless coroutines explaineddekorte.com

“It looks like what they’re doing are stackless user level threads and this means they don’t play nice with C calls as they don’t allow calling into C and then back into the language (as they can’t save the C stack). This may not sound like a problem until one considers how almost all C library bindings involve callbacks (xml parsers, graphics, audio, media processing, networking, etc).”

Caution: the post is 3 years old.

Jun 30, 2009
#stackless #coroutines #c #dekorte
Conference On Emerging Programming Languages

“An event to bring together bright folks working on unfinished or recently finished programming languages. Even relatively young languages like Scala would not qualify; this event is all about the sharpest part of the cutting edge.”

The most interesting one is ooc — another attempt to add objects, inheritance and improve packaging in C. via Steve Dekorte
Jun 29, 2009
#ooc #dekorte #event #cutting edge
Jun 25, 2009
#tokyocabinet #db
Snow Leopard with legacy macports and rubygems

We assume you had Leopard with standard Ruby shipped with OS, tons of macports and rubygems already installed. Then you install Snow Leopard on top of it (not clean install).

The problem is that standard 10.6 dynamic libraries all went 64 bit and could not be linked with 32 bit code. This could be fixed by rebuilding/reinstalling all the macports and rubygems.

1. Install the latest Xcode shipped with Snow Leopard.

2. “port” command will fail with a message about incompatible Tcl architecture. The proper version of macport is 1.8 which is not released yet. You can obtain it from SVN trunk and built it by hand (./configure && make && sudo make install). I have also added trunk version of ports to sources.conf (see the link above for instructions) to be sure that I have the latest SL-compatible ports in the list. Maybe this is was wrong assumption, but it worked for me just fine.

3. Remove all ports:
$ sudo port -f uninstall installed

4. Update rubygems to 1.3.1 at least (please google for instructions).

5. Remove vendor gems (gem uninstall refuses to remove them and fails to do batch remove):

$ gem list | cut -d" " -f1 > installed_gems
$ sudo mv /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8.bak
$ sudo mkdir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

Note: installed_gems file contains a list of all installed gems so that you can cat and xarg it for installing all gems back.

6. Uninstall all gems

$ sudo gem list | cut -d" " -f1 | xargs sudo gem uninstall -aIx

7. Make the rubygems use 64 bit architecture.

$ cat installed_gems | xargs sudo env ARCHFLAGS="-Os -arch x86_64 -fno-common" gem install --no-ri --no-rdoc

Note: it is NOT i686 (as I thought it should be), it is x86_64 instead.

Here are convenient aliases for “sudo gem install” for both architectures:

alias sgi32="sudo env ARCHFLAGS=\"-Os -arch i386 -fno-common\" gem install --no-ri --no-rdoc"
alias sgi64="sudo env ARCHFLAGS=\"-Os -arch x86_64 -fno-common\" gem install --no-ri --no-rdoc"


You may also put alias sgi="sgi64" in your .bash_login on snow leopard.


Now we all can proceed doing productive work. \o/


References:
1. http://www.nabble.com/-MacPorts—19446:-openssl-fails-to-compile-on-x86_64-td23247203.html
2. http://jaredonline.posterous.com/got-mysql-to-work-with-rails-in-mac-os-106-sn
3. http://cho.hapgoods.com/wordpress/?p=158

Jun 21, 20093 notes
#snow leopard #rubygems #macports
64 bit transition guidedeveloper.apple.com

“Rule 1. The sum of a signed value and an unsigned value of the same size is an unsigned value.”

Jun 19, 2009
#apple #osx #64bit #i686 #64
Why Apple keeps iPhone specifications quietappleinsider.com

“If developers are allowed to write "to the hardware,” the result is a broken platform where the vendor can’t move forward without breaking the apps.“

Jun 12, 20091 note
#apple #design #platform #hardware #iphone #specifications #specs
Grand Central Dispatch briefimages.apple.com

Apple added closures support to C, C++ and Objective C with lightweight threading and multicore balancing.

x = ^{ printf(“hello world\n”); }

Jun 9, 2009
#closures #blocks #c #objc #gcd
Snow Leopard

Snow Leopard shows a rare case when upgrade brings you more valuable performance and bug fixes rather then incredible new features.

Jun 9, 2009
#leopard #fix #apple
Steve Dekorte on programming language shootouts

“Writing a Mandelbrot set calculator in a high level language is like trying to run the Indy 500 in a bus. While it might be amusing for a car magazine to test circuit times for various busses on a race course, it really tells potential bus buyers very little about which bus they should buy as the problem of cost efficiently maximizing transportation throughput on normal roads involves different tradeoffs than the problem of no-expense-spared maximization of transportation speed on an extremely windy road.”

Jun 8, 2009
#shootout #dekorte #quote #performance #measurment
CSS box model

W3C box model (width specifies pure content area width) represents bottom-up philosophy where content specifies the area for itself. Parent elements should adapt to it.

IE6 box model (width specifies content area with borders and paddings) represents top-down philosophy where designer specifies available spaces for nested elements.

In fact, content designers don’t care about the container width and html designers think better in terms of IE6 box model. Thanks to stupid standards, we all have to make additional calculations in our heads when working with styleshits.

Jun 3, 2009
#boxmodel #css #w3c
"Type hints" syntax suggestion for Ruby

According to previous note on interfaces in dynamically typed languages, it would be great if the API could specify type expectations even easier than a to_type message send to each argument in method body.

class Person
  def initialize(name.to_s, birthday.to_date = DEFAULT_DATE)
    ...
  end
end

Should be interpreted as:

class Person
  def initialize(*args)
    args.size == 2 or raise ArgumentError 
    name = args[0].to_s
    birthday = (args[1] || DEFAULT_DATE).to_date
    ...
  end
end

This idea can be applied to other languages as well.

Jun 3, 2009
#ruby #syntax #hints #types
Reading code is hard

Why’s that? Consider Dostoevskiy’s “Crime and Punishment”: it is just 1 Mbyte. And what size is your codebase?

Jun 3, 2009
#code #question
Interfaces in dynamic object-oriented languages

Object interface is a set of messages with defined behavior the object should respond to.

In statically typed languages, interface is required by type declaration. In dynamically typed languages this is done by telling object of unknown type to cast itself to the desired type.

# User's code expects object responding to #to_page
# when casted to page, we expect proper #render and #size behavior
class SomeController
  def process(object)
    page = object.to_page
    page.render
    page.size
  end
end


# 1. Page class with #to_page interface returning self
class Page
  def to_page
    self # return self since it is already a page
  end

  # page public api

  def render 
  end

  def size
  end
end

# 2. Non-page class with #to_page interface
class AtomicBomb
  def to_page
    # return a relevant article
    Page.wikipedia_article("Nuclear weapon")
  end
end

# 3. Class without #to_page, but with #render method
# fails with "object does not respond to #to_page" exception
# and does not cause undesirable side effects
class Foo
  def render
    # very specific nasty rendering method
  end
end

# 4. Class without #render
# fails with "object does not respond to #to_page" exception 
# rather than with less descriptive "object does not respond to #render"
class Baz
end

This technique minimizes duck typing collisions by reducing the number of exposed methods to a single “to_{unique_type_name}” method. It also protects you from inventing obtrusive method names with type prefixes such as “page_render” or “page_size_in_characters” (see example above).

The rule of thumb:

1. When API consists of more than one method, introduce #to_my_type method

2. Whenever you receive an object from an unknown source (e.g. defined in a different file), use explicit type casting with #to_some_type method.

Note: never ever make others ask about the kind of an object using #respond_to?. This method should be used for legacy code and indicates possible duck typing issues.

Also, #is_a?(SomeAbstractInterfaceModule) is considered badly designed compared to #to_* methods.

Jun 2, 20093 notes
#interface #protocol #design #code #language

May 2009

Correct BlankSlate in Ruby
class BlankSlate
  class <<self; alias __undef_method undef_method; end
  alias __instance_eval instance_eval
  ancestors.inject([]){|m,a| m + a.methods }.uniq.
    each { |m| (__undef_method(m) rescue nil) unless m =~ /^__/ }
end

class MyProxy < BlankSlate; end

Note 1: ancestors.inject{…} ensures that all Kernel methods like :p are properly removed.

Note 2: alias __instance_eval could be safely removed if you don’t need this method.

May 30, 2009
#ruby #blankslate #code #example
Steve Dekorte on torturedekorte.com
May 29, 2009
#torture #quote #link
The most detailed description of graphd, the metaweb storage engineblog.freebase.com

“Giving every piece of data a fixed identity, is radically different from the relational model which deals only with sets of values and leaves the notion of identity up to the application. Working with identities as a first-class notion is essential if schema is to be flexible. Long before we can agree on the exact shape of the data used to represent a person or a building, we can agree that individual people or buildings exist and that they have certain obvious attributes that we might want to record: height, address, builder, etc.”

May 28, 2009
#metaweb #graphd
The End of an Architectural Era (It's Time for a Complete Rewrite)vldb.org
May 28, 2009
#paper #rdbms #db
Worlds/JSvpri.org

JavaScript transactional memory extension

May 28, 20091 note
#js #transactions #worlds #paper
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
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