Skip to content

Instantly share code, notes, and snippets.

View yurko's full-sized avatar

Yurko Bregey yurko

View GitHub Profile
@yurko
yurko / rewrite_git_hist.sh
Created October 17, 2018 07:47
change commits author
# https://help.github.com/articles/changing-author-info/
#!/bin/sh
# remove backup
rm -f .git/refs/original/refs/heads/master
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Name"
@yurko
yurko / google-dorks
Created May 31, 2018 10:24 — forked from stevenswafford/google-dorks
Listing of a number of useful Google dorks.
" _ _ "
" _ /|| . . ||\ _ "
" ( } \||D ' ' ' C||/ { % "
" | /\__,=_[_] ' . . ' [_]_=,__/\ |"
" |_\_ |----| |----| _/_|"
" | |/ | | | | \| |"
" | /_ | | | | _\ |"
It is all fun and games until someone gets hacked!
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
@yurko
yurko / anagram.rb
Last active October 1, 2018 15:08
algos jff
def anagram? a, b
counts = ->(word) { word.each_char.with_object(Hash.new(0)) { |c, h| h[c] += 1 unless c =~ /\s/} }
counts[a] == counts[b]
end
@yurko
yurko / reorder.rb
Last active February 18, 2019 13:50
railway oriented
module Carousel
class Reorder
extend Dry::Initializer
include Dry::Monads::Either::Mixin
param :scope, reader: :private
param :params, reader: :private
def call
context = OpenStruct.new(
@yurko
yurko / examples.sh
Last active May 30, 2018 12:57
shell
# kill by port
sudo kill -9 $(lsof -i :3000 -t)
# wget with range
wget --user user --password password http://example.com/{0..n}.jpg
# scp
scp [email protected]:projects/dev.log /home/dev/dev.log
# Bulk rename
group.admins << user
user.admin? # => true
user.editor? # => false
class Group < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
has_many :admins, :through => :memberships, :source => :user,
:conditions => "memberships.role = 'admin'" do
@yurko
yurko / class_new.rb
Last active May 30, 2018 13:16
Ruby tips&tricks from different sources
class Class
def new(*args, &block)
obj = allocate
obj.initialize(*args, &block)
# actually, this is obj.send(:initialize, …) because initialize is private
obj
end
end
@yurko
yurko / carrierwave
Last active May 30, 2018 13:17
image and video processing
convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% source.jpg result.jpg

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger