Skip to content

Instantly share code, notes, and snippets.

View emilpetkov's full-sized avatar

Emil Petkov emilpetkov

View GitHub Profile
@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
#
@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|
@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:

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:

@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
@myobie
myobie / mountain-lion-brew-setup.markdown
Created February 18, 2012 20:14
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@AndrewRadev
AndrewRadev / search.rb
Created February 10, 2012 15:07
Grep (ack) for a string within all required gems
require 'bundler'
paths = Bundler.load.specs.map(&:full_gem_path)
system("ack 'Memoizable' #{paths.join(' ')}")
" This script makes it easy to generate the preview of a file using some
" external program. This could probably be used for any kind of file that
" requires some preprocessing before usage, like coffeescript or markdown.
"
" The preview's parameters are defined using the function SetupPreview. Its
" first parameter is the extension of the processed filetype, the second one
" is the shell command to execute, with %s being replaced by the current
" file's filename.
"
" Examples:
@connor
connor / .jshintrc.js
Created January 11, 2012 22:20
jshintrc example
// NOTE: I added the .js extension to this gist so it would have syntax highlighting. This file should have NO file extension
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
@AndrewRadev
AndrewRadev / qf.vim
Created December 2, 2011 20:14
Delete lines from the quickfix window (with undo)
" Place in ftplugin/qf.vim
xnoremap <buffer> d :DeleteLines<cr>
nnoremap <buffer> dd :DeleteLines<cr>
nnoremap <buffer> u :UndoDelete<cr>
if !exists(':DeleteLines')
let b:deletion_stack = []
" Delete by a pattern (with undo placing them all on top):