Oleg Andreev

Month
Filter by post type
All posts

Text
Photo
Quote
Link
Chat
Audio
Video
Ask

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
Feb 12, 2009
#trace trees #vm #paper #pdf #tree
English—2

And when they drop back to French, discussion becomes a complete nonsense.

Feb 11, 2009
#english #french #nonsense #stupid
English

At this very moment I’m attending a meeting at The Big Company in France. There are six french folks around me speaking English instead of French. The only reason for that is me — I don’t speak French. It’s a bit hard for everyone to speak and understand English and initially I was a little bit ashamed of that. But soon I realized that the difficulty of speaking English makes everyone to focus on the essentials and prevents spoiling everyone’s time on the nonsense. Sweet.

Feb 11, 2009
#language #communication #france #french #english
“The current version of TeX is 3.1415926; it was last updated in March 2008. The design was frozen after version 3.0, and no new feature or fundamental change will be added, so all newer versions will contain only bug fixes. Even though Donald Knuth himself has suggested a few areas in which TeX could have been improved, he indicated that he firmly believes that having an unchanged system that will produce the same output now and in the future is more important than introducing new features. For this reason, he has stated that the “absolutely final change (to be made after my death)” will be to change the version number to π, at which point all remaining bugs will become features. Likewise, versions of METAFONT after 2.0 asymptotically approach e, and a similar change will be applied after Knuth’s death.”—Wikipedia article on TeX versioning. By the way, Perl 6 milestones are numbered with 2 Pi decimal digits.
Feb 10, 2009
#versions #pugs #perl #perl6 #tex #knuth #humor #pi
Zed Shaw's great presentation on how to save your soul in the corporate worldvimeo.com

See also slides (in a form of Factor plain text source code)

Feb 10, 2009
#factor #ruby #java #zed #shaw #stupid #video #presentation #slides #howto
Code colorizing QuickLook plugin code.google.com
Feb 10, 2009
#mac #quicklook #code #colorizing
[idea] Cloning subdirectory from a git repository

Apparently, there’s no conceptual problem with cloning a subdirectory like:

$ git clone git@server:project.git/docs/howto

You should just keep track of those tree objects referencing to “/”, “/docs” and “/docs/howto”, but fetch no references except children of the “/docs/howto” tree.

Feb 9, 20091 note
#git #idea #design
Better package system

There’s a problem in Ruby: what if your application requires two libraries and both of them require incompatible versions of another library?

API designers who are smart enough create a namespace for each major version (MyLib::API1, MyLib::API2 etc.) so that you can have multiple versions of the same code in run time.

There’s a better solution however. Io language does not make you to modify the global state: source code can be loaded in any other object. This means that you don’t have to pollute library code with a version-based namespaces but you still able to load as many instances of the library as you want. Just make sure you keep them in your private objects.

Dreams come true:

MyParser := Package load(“XMLParser”, “e1fc39a02d786”)

Feb 9, 2009
#ruby #io #package #versions #api
Ruby and Rails dictionaries for Mac OS Xpriithaamer.com

You definitely should try these.

Feb 9, 20091 note
#ruby #rails #dictionary #mac #utility
Exceptions

Exceptions are meant to be… ehm… exceptional. Exceptions are thrown when the code could not be executed further. They are meant to be thrown right at the point where something went wrong and passed up the stack till the program termination. Programmer should only provide “ensure” (in Ruby; or “finally” in Java) block to clean up. Programmer should never use “catch”/“rescue” block. Never.

There’s one little thing, however.

Sometimes you run your program and get silly exceptions like “connection lost” or “division by zero”. You become unhappy about it and you decide to implement an interface to deal with such errors. For example, when connection is lost you could show a message or do something smart (depends on the purpose of your program, of course).

But please remember: never ever catch exceptions you don’t know about (no “rescue nil” or “rescue => e”!). You should be very picky at what you are catching. Uncaught exception simply pops up in a system message or a log entry, so you can learn it. But silently caught exception might hide some nasty error from your eyes. And you wouldn’t be able to see in a stack trace what had happened few milliseconds before.

Feb 6, 2009
#exceptions #oop
Re: Stop picking on alias_method_chain

Both Ben and Yehuda are wrong. They both use messy metaprogramming where Ruby has a nice solution already. It is a chain of modules and a super method. If the base functionality is provided in a module it looks like this: module BaseFeatures def hello "Hello, world!" end end module AnyGreetingPlugin def hello(arg = "world") super.sub(/world/, arg) end end class MyConfiguration include BaseFeatures include AnyGreetingPlugin include AnotherPlugin end If your base functionality is packed in a class, rather than in a module — no problem, the solution is pretty much the same: class MyConfiguration < BaseFeatures include AnyGreetingPlugin include AnotherPlugin end

Now let me respond to each point from the Ben’s article:

1. “The method names don’t properly describe what is going on”. Module name describes what particular functionality it adds to the methods it contains.

2. “The base method shouldn’t care what other modules are doing, modularity is broken”. That’s not the case when you use regular modules.

3. “Logic is not 100% contained”. Logic is 100% contained: no magical macros anywhere.

4. “Promotes messy code”. Again, nothing to even seem messy.

5. “Exposes a documentation flaw”. When you think modules it is easy to separate concerns and understand how every little aspect of functionality affects everything else. You don’t have to speak any other language except Ruby. You think of module chains and message passing: no structure is created dynamically where not necessary. Only thing you have to do: describe in the documentation what this particular class or module is supposed to do. Then provide examples of a default configurations (when some modules are included in a single class) to make the picture complete. Respect the language. Keep it simple, stupid.

Feb 3, 20092 notes
#ruby #metaprogramming #design #api #kiss
Re: refactoring data models
(e-mail conversation with a colleague)

class User < ActiveRecord::Base; end
class Artist < User; end
class Investor < User; end

I don’t understand why this would be a very bad idea ? All the users are stored in a same table as they have a lot of attributes and not much differ…

This starts with a naming of a user. As i wrote you recently, “User” name completely hides “role” from you, so it seems natural to put all the roles into User model. However, huge models tend to become harder and harder to modify and understand.

If you think of it that way:

- Person - holds authentication info
- Artist - holds info about music and albums
- Investor - holds info about artists and finance
the following becomes easy to play with:

- Person has many Artists (say, i can create several accounts for a number of my bands)
- Artist info can be edited by a group of People (my band members would like to update the news page/wiki/whatever)
- I (as a person) can represent several investors, or none at all.
- Investor can manage a number of artists, and/or a single artist can have several investors.

The reason to separate models by tasks is the very same as to separate objects from the top global Object class into more specific ones.

Speaking scientifically, it is just about “normalization” of a relational database.

If you have duplicating attributes, you have three equally good options (depending on your situation):

1. Mix them in using a module (e.g. “EntityWithTitleAndDescription”) if the duplication is just a coincidence, not a big deal (just to put some duplication into a single file to keep things cleaner).

2. Implement a separate model and associate it with appropriate models (e.g. “Account” could mediate between Person and Project to manage wikis/pages/documents/artists/etc. to avoid hardcore polymorphism between Person and Project). This is the case in a Basecamp-like app, where people have individual data as well as data, shared by a group (project).

3. Leave duplication as is: Coincidence pattern

Sometimes you have to have STI, but i believe this is not the case. E.g. i have PublicFolder and Inbox subclasses of a class Folder because they are a little special per se, not by their association to other folders.

Feb 3, 20091 note
#ruby #models #design #refactoring #sti #dry
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