TIL by Timur


Гео и язык канала: не указан, не указан
Категория: не указана


Notes about software development and other interesting tech stuff

Связанные каналы

Гео и язык канала
не указан, не указан
Категория
не указана
Статистика
Фильтр публикаций


It is possible to save macros in vim. Add let @q = 'macro contents’ to your ~/.vimrc. Then in next vim session you can just call your presaved macro.


Bundles maybe useful if you need to transfer a git project to someone, but the project isn’t connected to a bare repository.


It is possible to create a git archive with git bundle create file.bundle master, transfer it to another machine and clone a new repository from it with git clone -b master file.bundle.


In #ruby you can split enumerable on two arrays by the result of a block evaluation: (1..6).partition { |v| v.even? } #=> [[2, 4, 6], [1, 3, 5]]


https://hub.github.com an awesome tool for working with github from a command line.


#curl can decompress gzipped response with --compressed flag.


#elasticsearch can run in-memory cluster for testing purposes.




#vim has insert normal mode that let you execute a single command and then it brings you back to insert mode. Press ^o (ctrl-o) during insert mode in order to switch to insert normal mode.


#vim allows to disable search highlighting until next search with :noh.


http://dejimata.com/2017/5/20/the-ruby-module-builder-pattern

This interesting pattern demonstrates the real power of metaprogramming in #ruby. The implementation is so neat and tricky. Since ruby allows to generate anonymous modules dynamically with Module.new, a class, that is inherited from a Module, will generate an anonymous module on initialization. So it is possible to include an object of this class in another class, because object will be the module itself. Mind blown.




Actually I din't learn this today, but I want to continue on REPL in #ruby topic. Today feature is really useful, but little-known.
Working with interpreter frequently leads you to situations where you don't assign a latest result of evaluation to a variable, but then you realise that you definitely need it. Instead of pressing up arrow or ^P and repeating last command with assignment you can just type _ and work with it. The result of latest evaluation is automatically stored in _ temporary variable.




REPL in #ruby always returns a result of evaluation. In some cases you don't want to see the result, you just need it for further operations. Long output takes time to render, for example if you need to instantiate lots of objects from a database. Hovewer the interpreter can be tricked by combining your operation with return nil like this: contents = Content.in(id: ids).to_a; nil.


Finding characters in a line with f, F, t, T in #vim can be repeated with ; for a next and , for a previous occurrence.


REPL in #ruby allows to change binding context to objects. It works for pry and irb, just use irb method instead of pry.


hello world

Показано 18 последних публикаций.

86

подписчиков
Статистика канала