Skip to content

Instantly share code, notes, and snippets.

Avatar

Yurko Bregey yurko

View GitHub Profile
@yurko
yurko / rewrite_git_hist.sh
Created Oct 17, 2018
change commits author
View rewrite_git_hist.sh
# 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="old@email.com"
CORRECT_NAME="Your Name"
@yurko
yurko / google-dorks
Created May 31, 2018 — forked from stevenswafford/google-dorks
Listing of a number of useful Google dorks.
View google-dorks
" _ _ "
" _ /|| . . ||\ _ "
" ( } \||D ' ' ' C||/ { % "
" | /\__,=_[_] ' . . ' [_]_=,__/\ |"
" |_\_ |----| |----| _/_|"
" | |/ | | | | \| |"
" | /_ | | | | _\ |"
It is all fun and games until someone gets hacked!
View 0. Ruby Meta Programming - spells covered.md
  • 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
View anagram.rb
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 Feb 18, 2019
railway oriented
View reorder.rb
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(
View examples.sh
# 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 dev@123.123.123.123:projects/dev.log /home/dev/dev.log
# Bulk rename
View Join Attributes on a HMT.rb
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
Ruby tips&tricks from different sources
View class_new.rb
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
image and video processing
View carrierwave
convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% source.jpg result.jpg
View gist:4c44d23452b9e87612adb317137147ae

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