Skip to content

Instantly share code, notes, and snippets.

View bobishh's full-sized avatar
🐵
oi

Bogdan Agafonov bobishh

🐵
oi
  • Berlin, Germany
View GitHub Profile
@bobishh
bobishh / global_replace.sh
Created January 10, 2018 23:34
String replacement perl oneliner for multiple files
perl -0777 -pi -e 's/CRAZY/REGEXP/g' *FILES*
@bobishh
bobishh / active_record_log_subscriber.rb
Created June 14, 2017 09:49
Initializer which shows which line generated SQL
# coding: utf-8
module LogQuerySource
def debug(*args, &block)
return unless super
backtrace = Rails.backtrace_cleaner.clean caller
relevant_caller_line = backtrace.detect do |caller_line|
!caller_line.include?('/initializers/')
end
@bobishh
bobishh / gif_via_imagemagick.bash
Created May 17, 2017 11:48
Create gif from jpeg via imagemagick
#!/bin/bash
delay=$1
resize=$2
output=$3
file_list=$4
convert -delay $delay -resize $resize $file_list -loop 0 $output
module Writeable
module Mixin
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def retrieve_connection
@pool ||= connection_handler.connection_pool_list.select do |p|
p.spec.config[:writeable] == true
class JoinFormatter
def initialize(separator = '', default = '')
@default = default
end
def format(elements)
res_string = elements.join ''
return @default if res_string == ''
res_string
end
@bobishh
bobishh / inheritance.coffee
Last active September 14, 2016 09:26
CoffeeScript inheritance model
class Animal
constructor: (@name) ->
@kind = 'animal'
say_hello: ->
alert "Hello human! I'm #{@kind} named #{@name}"
alterVoice: (voice) ->
@voice = voice
class Dog extends Animal
constructor: (@name) ->
#create dump:
pg_dump -h <HOSTNAME> -U <USERNAME> -b -Fc <DBNAME> | bzip2 -c > <WHERE_TO_DUMP>.bz2
#restore dump:
bzip2 -d -c <FILE> | pg_restore -h <HOSTNAME> -U <USERNAME> -d <DBNAME> -Fc -O -c
# fish-shell
for branch in (git branch --merged master | grep -v "^\ *master")
git push origin :(echo $branch | sed 's/\ *//')
end
@bobishh
bobishh / gist:79d415cecff98505eeea
Last active August 29, 2015 14:26 — forked from sgergely/gist:3793166
Midnight Commander Keyboard Shortcuts for Mac OSX
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name