Skip to content

Instantly share code, notes, and snippets.

View emilpetkov's full-sized avatar

Emil Petkov emilpetkov

View GitHub Profile
@headius
headius / gist:1234935
Created September 22, 2011 14:38
OS X 'pickjdk' command with single-command selection and updated JDK location
#!/bin/bash
#
# Provides a function that allows you to choose a JDK. Just set the environment
# variable JDKS_ROOT to the directory containing multiple versions of the JDK
# and the function will prompt you to select one. JAVA_HOME and PATH will be cleaned
# up and set appropriately.
_macosx()
{
if [ $(uname -s) = Darwin ]; then
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@sinisterchipmunk
sinisterchipmunk / LICENSE
Last active October 23, 2024 21:10
tar, gzip, and untar files using ruby in memory without tempfiles
Copyright (C) 2011 by Colin MacKenzie IV
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@headius
headius / gist:1341547
Created November 5, 2011 14:09
redblack tree impl perf on JRuby (OpenJDK 6, 7, HEAD) and Ruby 1.9.3p0
# Flags passed to JRuby are to enable fastest options for that JVM version
# JAVA 6
system ~/projects/redblack $ pickjdk 1
New JDK: 1.6.0.jdk
system ~/projects/redblack $ jruby -X+C bm1.rb 10
2.577
1.758
@AndrewRadev
AndrewRadev / nerdtree_fix.vim
Created November 11, 2011 18:28
When :edit-ing in NERDTree, open the file in the closest buffer instead
" Whenever you execute an `:edit somefile` command with the cursor in the
" NERDTree, the file gets edited in the NERDTree buffer, which is usually not
" something you want. This autocommand attempts to edit the given file in the
" closest non-NERDTree buffer instead.
"
" It's fairly hacky, but seems to work. I'll probably use it myself, so I'll
" try to remember to update it if I find any problems.
augroup AvoidEditingNERDTree
autocmd!
@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):
@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`.
" 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:
@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(' ')}")
@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.