Skip to content

Instantly share code, notes, and snippets.

View abachman's full-sized avatar
🙌
good times

Adam Bachman abachman

🙌
good times
View GitHub Profile
@abachman
abachman / mkdir_and_open.vim
Created December 8, 2010 21:53
Open an file for editing, creating its path if said path doesn't already exist.
" Usage:
"
" :Me ~/path/to/my/new/file.txt
"
" creates /home/username/path/to/my/new with `mkdir -p` if it doesn't exist
" and then opens file.txt
"
function! Mkdire(path)
let l:newpath = fnamemodify(expand(a:path), ":p:h")
@abachman
abachman / logger.rb
Created December 14, 2010 18:56
an example of a custom logger that mimics Rails' internal logging

So now I can log from anywhere in the application by saying:

MyPlugin.logger.debug("This is a debug level statement")

which outputs:

DEBUG This is a debug level statement
@abachman
abachman / ability.rb
Created December 26, 2010 17:50
using RoleModel and CanCan to make roles and permissions easy
# https://github.com/ryanb/cancan
class Ability
include CanCan::Ability
def initialize(user)
# All abilities are scoped to roles
if user.is? :admin
# can :do, Stuff
end
@abachman
abachman / gist:757727
Created December 28, 2010 21:14
shh... don't tell anyone else
" http://vimgolf.com/challenges/4d1a34ccfa85f32065000004
noremap E yypjddjj
" http://vimgolf.com/challenges/4d1a4d82a860b7447200008d
noremap <silent> <leader>v mv:%s/\s\+$//e<CR>:%s/\t/ /e<CR>`v
" this one was already in my .vimrc
@abachman
abachman / gist:776286
Created January 12, 2011 15:21
semantic blueprint sass example
#left-column
!left_columns = floor(!blueprint_grid_columns / 2)
+column(!left_columns)
#right-column
!right_columns = ceil(!blueprint_grid_columns / 2)
+column(!right_columns)
@abachman
abachman / baltimore-socrata.rb
Created January 26, 2011 17:34
demo of the socrata opendata api
# before: gem install socrata
require 'socrata'
sapi = Socrata.new :base_uri => "http://data.baltimorecity.gov/api"
puts sapi.view("n4ma-fj3m") # Parking Citations
@abachman
abachman / gem-lister.rb
Created February 9, 2011 19:14
generate a list of the currently available gems and links to their rubygems.org page.
#!/usr/bin/env ruby
require 'open-uri'
puts "<html><head></head><body><ul>"
while line = gets
gemname = line.chomp
url = "http://rubygems.org/gems/%s" % gemname
success = false
@abachman
abachman / lazy_loading.html
Created February 9, 2011 21:58
example of lazily loading images on arbitrary events using the JQuery lazyload plugin
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<!-- from: https://github.com/tuupola/jquery_lazyload -->
<script src='https://github.com/tuupola/jquery_lazyload/raw/master/jquery.lazyload.js'></script>
<script>
$(function () {
# proxying through apache to a local rails instance, http & https
# apache *.conf file
<VirtualHost *:80>
ServerName psl.localhost
ServerAlias cms.psl.localhost
ServerAlias *.psl.localhost
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
# there are two players, player A and player B
# the board has nine empty spaces, three by three grid
# game starts with player A
# game continues with players alternating turns making marks in spaces until game ends
# a legal move is when a player puts a mark in an empty space
# the game ends when either there have been nine moves or tictactoe has been acheived
#player = A or B
# there are two players, a and b