Node.js Development Enverionment by Milnex

5271e1410e37d5af76347394fe875f9e?size=52
  1. Install nvm - node.js version manager curl https://raw.github.com/creationix/nvm/master/install.sh | sh
  2. Add the following line into ~/.zshrc or ~/.bashrc or whatever dotfiles your shell uses

    [[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh  # This loads NVM
    
  3. Install latest Node.js

    nvm install latest
    

#nodejs #nvm #npm

Workplace matters. by makaroni4

E302c3320cd14b02cbe237b479d7f884?size=52

Coding 100% of my time on a laptop I noticed that I sit wrong and my spine is always bent. So I bought this amazing thing to fix this:

laptop

By now the experiment is OK – I feel really good, sit right with monitor in front of my eyes. What do you do to be a healthy coder?

#workplace

Force showing scroll on Mac with css by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

As we know we don't see scrolls on #OSX Lion and above by default, but sometimes we have to show them to user because of #UX.

We can do it just by adding scroll's styles. For example:

#myelement::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 8px;
}

#myelement::-webkit-scrollbar-track {
  background-color: #eee;
  border-radius: 8px;
}
#myelement::-webkit-scrollbar-thumb {
  border-radius: 8px;
  background-color: #666;
}

#html

objective-c print NSData as binary string by Arthraim

A0eef010278ab0859ea2424aea0f1e28?size=52
//...
NSData *somedata = ...
for (int i = 0; i < [somedata length]; i++) {
    const uint8_t * databytes = [somedata bytes];
    [self getBitStringForInt:(uint8_t)databytes[i]];
}
//...

- (void)getBitStringForInt:(int)value {
    NSString *bits = @"";
    for(int i = 0; i < 8; i ++) {
        bits = [NSString stringWithFormat:@"%i%@", value & (1 << i) ? 1 : 0, bits];
    }
    NSLog(@"%@", bits);
}

#objectivec via: http://stackoverflow.com/a/5076980/440489

Sync Github fork repo with origin/master by makaroni4

E302c3320cd14b02cbe237b479d7f884?size=52

When contributing to open source you may face a problem – your fork is outdated. There could be another scenario – git repo in Github is just mirror of perforce repo, so after your pull request is merged there won't be your commits in repo and you again will have to sync fork and origin.

git remote add upstream git://github.com/username/repo.git
git fetch upstream
git checkout master
git reset --hard upstream/master  
git push origin master --force

#git

Save an image from url to a file using Dragonfly by dskecse

C38db09277e3ce12966c1a030265a1c5?size=52

Given an image accessor field cover_image for an Image model, u can use a cover_image_url accessor for assigning directly from a url (simply using a string). To make it does what u want just save the corresponding object.

example:

img = Image.new
img.cover_image_url = 'http://img.youtube.com/vi/wh-XcmRQFhI/0.jpg'
img.save

BTW: what is your favourite image uploader in rails?

#dragonfly #rails

Custom helper methods of State Machine (ruby) by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

I have a lot of code in my project like the following:

class Animal < ActiveRecord::Base
  state_machine do
    around_transition :on => :sure do |animal, _, block|
      animal.transaction do
        block.call
        animal.do_things_on_sure
      end
    end
  end
end

around_transition looks ugly and repeats for many classes.. Lets refactor it. More under the cut