This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Foo | |
| include ActiveSupport::Configurable | |
| class << self | |
| def configure | |
| yield config | |
| end | |
| end | |
| end | |
| Foo.configure do |config| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cat, print file.bin's binary content | |
| cat file.bin | |
| # => | |
| # DUMP - convert binary content to hex string | |
| xxd -p file.bin | tr -d '\n' | |
| # => 48656c6c6f20576f726c640a | |
| # RESTORE - convert hex string to binary content | |
| echo 48656c6c6f20576f726c640a | xxd -r -p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DUMP | |
| mkdir -p ~/backup | |
| dpkg --get-selections > ~/backup/Package.list | |
| sudo cp -R /etc/apt/sources.list* ~/backup/ | |
| sudo apt-key exportall > ~/backup/Repo.keys | |
| # RESTORE | |
| sudo apt-key add ~/backup/Repo.keys | |
| sudo cp -R ~/backup/sources.list* /etc/apt/ | |
| sudo apt-get update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| params = Hash[[*'a'..'j'].zip([*1..10])] # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5, "f"=>6, "g"=>7, "h"=>8, "i"=>9, "j"=>10} | |
| slice_keys = ['a','f','g'] | |
| filter = -> (key, _) { slice_keys.include?(key) } | |
| slice = params.select &filter | |
| params.delete_if &filter | |
| slice # => {"a"=>1, "f"=>6, "g"=>7} | |
| params # => {"b"=>2, "c"=>3, "d"=>4, "e"=>5, "h"=>8, "i"=>9, "j"=>10} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'digest' | |
| result = Hash.new() { |hash, key| hash[key] = [] } | |
| Dir['**/*'].each do |file| | |
| if File.file?(file) | |
| result[Digest::MD5.new.file(file).to_s] << file | |
| end | |
| end | |
| result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ls **/en.yml **/de.yml | grep -v spec| tar -czf archive.tgz -T - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foo = Namespace::To::Module.instance_method(:foo) | |
| obj.class.send(:define_method, :foo, foo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ary.inject(Hash.new(0)) { |total, e| total[e] += 1 ;total} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'yaml' | |
| class Hash | |
| def deep_reject(&blk) | |
| self.dup.deep_reject!(&blk) | |
| end | |
| def deep_reject!(&blk) | |
| self.each do |k, v| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for f in `git ls-files "*.rb"`; do ruby -c $f | grep -v "Syntax OK" ; done |