George Opritescu

Developer from somewhere

find all git commits that contain a file

If you want to find commits that included a now deleted file, you can run:

git log --follow -- path/to/file
Read More
git

brew readline upgrade issue

Updated readline, and after that got this error:

    Sorry, you can't use byebug without Readline. To solve this, you need to
    rebuild Ruby with Readline support. If using Ubuntu, try `sudo apt-get
    install libreadline-dev` and then reinstall your Ruby.
/Users/geo/.rvm/gems/ruby-2.3.0@timers/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require': dlopen(/Users/geo/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
  Referenced from: /Users/geo/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
  Reason: image not found - /Users/geo/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle

Turns out it was caused by upgrading to readline 7.0. Fixed by:

brew uninstall readline # this left 6.3 still in the system
brew link readline --force
Read More

check if an association is already loaded

Following can be useful in tracking N+1 queries, imagine you have a User with many Photos:

user.photos.loaded?

the code above would tell you if the association has been already loaded. It proved useful when trying to track down a N+1 query when serializing to JSON.

Read More

call ember action from another action

If you need to call a different action from one of your actions, you can use:

this.send("nameOfOtherAction", someArguments)
Read More

iterm2 back in time

Alt-Cmd-B can allow you to go to a specific time in your terminal history ( ex. 10 min ago )

Read More

scrapy get item instead of list

ItemLoader

1
.add_css
returns a list, instead of a single value. To get the first value, use this in your item:

import scrapy
from scrapy.contrib.loader.processor import TakeFirst

class YourItem(scrapy.Item):
    description = scrapy.Field(output_processor=TakeFirst())
Read More

using pip and virtualenv from the user folder

Doing a:

python get-pip.py --user

installs pip just for the current user. To run it, I use:

~/Library/Python/2.7/bin/pip install -U virtualenv

The same goes for virtualenv:

~/Library/Python/2.7/bin/virtualenv someenv
Read More

filtering non-null values from json with jq

Given a json file, in the format:

{
  "content": [
    {"name":some_name},
    {"name": null}
  ]
}

The following command would extract only the entries where the name is not null:

cat file.json | jq '.content | .[] | select(.name != null) | {name: .name}'
Read More

css selector excluding class

This would find you all the elements that are

1
.some.class
but not
1
.some_other_class

$(".some.class").not(".some_other_class")
Read More

python virtualenv

Kind of similar to what rvm does:

pip install virtualenv
cd my_project_folder
virtualenv nameofenv
source nameofenv/bin/activate

Now you should see a prefix on the shell prompt, with the name of the environment. Afterwards, do:

pip install somepackage

and it will install it for a specific package. To get something akin to a Gemfile.lock do:

pip freeze > requirements.txt

And to do a bundle install:

pip install -r requirements.txt
Read More