Skip to content

Instantly share code, notes, and snippets.

View emilpetkov's full-sized avatar

Emil Petkov emilpetkov

View GitHub Profile
@AndrewRadev
AndrewRadev / diffsplit.vim
Last active May 22, 2018 14:45
Split a git diff in separate files to mirror the original repo layout
" Put this in plugin/diffsplit.vim.
"
" Executing :Diffsplit on a file, containing a git diff would open up a new
" tab, cd to a temporary directory, and distribute the changes into separate
" files, mirroring the repo layout. You can then use NERDTree or whatever you
" like to browse through the changes.
"
" Using it straight from the command-line is fairly simple and aliasable:
"
" git diff whatever | vim - -R +Diffsplit

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@bbatsov
bbatsov / devise.bg.yml
Created March 12, 2012 13:12
Bulgarian translations for Devise
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
bg:
errors:
messages:
expired: "е изтекъл, моля заявете нов"
not_found: "не е намерен"
already_confirmed: "е вече потвърден, моля опитайте да влезете в профила си с него"
not_locked: "не бе заключен"
not_saved:
@otaviomedeiros
otaviomedeiros / validate_with_matcher.rb
Created March 14, 2012 00:05
RSpec matcher for validates_with
# RSpec matcher for validates_with.
# https://gist.github.com/2032846
# Usage:
#
# describe User do
# it { should validate_with CustomValidator }
# end
RSpec::Matchers.define :validate_with do |validator|
match do |subject|
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@Svel
Svel / gist:2288892
Created April 3, 2012 02:34
git workflow production commit
# Inspired from https://www.braintreepayments.com/braintrust/our-git-workflow
# and some https://www.google.com/search?q=git%20workflow&hl=en searching
#
git checkout master
git merge --squash dev
msg="Version XXX";log=$(git log --format=" * %s" dev ^$(git log --merges -n 1 dev --format="%H")); echo -e "$msg\n\n$log" | git commit -F-
git checkout dev && git merge master
@jboner
jboner / latency.txt
Last active November 14, 2025 11:14
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@ihassin
ihassin / Reconnect
Created June 3, 2012 14:51
Reconnect to a lost database connection using an exception block trick (ruby, rails, mysql, activerecord)
def my_task
while(true) do
begin
database_access_here
rescue Exception => ex
begin
ActiveRecord::Base.connection.reconnect!
rescue
sleep 10
retry # will retry the reconnect
@AndrewRadev
AndrewRadev / grep.vim
Last active October 6, 2015 10:28
A simple :Grep
" Can be called in several ways:
"
" :Grep <something> " -> Grep for the given search query
" :Grep " -> Grep for the word under the cursor
" :'<,'>Grep " -> Grep in visual mode
"
command! -count=0 -nargs=* Grep call s:Grep(<count>, <q-args>)
function! s:Grep(count, args)
try
let original_grepprg = &grepprg
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection