Skip to content

Instantly share code, notes, and snippets.

View cpetschnig's full-sized avatar

Christoph Petschnig cpetschnig

  • powercloud GmbH
  • Leipzig, Germany
  • 00:38 (UTC +02:00)
View GitHub Profile
@cpetschnig
cpetschnig / create_user_mysql.sql
Created April 14, 2010 07:50
MySQL: Create DB user and set permissions
-- create new user and give permissions to all databases of names starting with "USERNAME_"
CREATE USER 'my_new_user'@'localhost' IDENTIFIED BY '9ixv[jX6g33yD#lZl#T5dV5l882_Y';
GRANT ALL ON `my_new_user\_%`.* TO 'my_new_user'@'localhost';
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@cpetschnig
cpetschnig / profiling-example.rb
Created November 16, 2010 15:51
Custom runtime evaluation/profiling
class Array
@@caller_counter = {}
def include_with_caller?(value)
key = caller[0,4].join('|')
@@caller_counter[key] = (@@caller_counter[key] || 0) + 1
include_without_caller?(value)
end
alias_method_chain :include?, :caller
def self.callers
@@caller_counter
@cpetschnig
cpetschnig / .irbrc
Created April 13, 2011 09:48
IRB customization: load wirble, looksee and awesome_print; cheat bundler
require 'rubygems'
@irb_extensions = []
def require_for_irb_with_fallback_for_bundler_constraints(gem_name, load_file = nil)
load_file ||= gem_name
begin
begin
require load_file
rescue LoadError => e
@eric
eric / linux_proc_name.rb
Created November 9, 2011 07:39
Update a process name in linux to change how it shows up in top and lsof
#
# Eric Lindvall <eric@5stops.com>
#
# Update the process name for the process you're running in.
#
# This will allow top, lsof, and killall to see the process as the
# name you specify.
#
# Just use:
#
@thomet
thomet / mysql_in_ramdisk.sh
Last active January 4, 2016 05:39
Creates a mysql database in a ramdisk with socket support (/tmp/mysql_ram.socket)
DEVICE=`hdiutil attach -nomount ram://2048000` # 2GB Ramdisk
diskutil erasevolume HFS+ "ramdisk" $DEVICE # mounted automaticaly in /Volumes/ramdisk
BASE_DIR=/usr/local/opt/mysql # MySQL home installed via Homebrew
DATA_DIR=/Volumes/ramdisk # Ramdisk home
SOCKET=/tmp/mysql_ram.sock # SOcket for the new mysql server instance
PID_FILE=/tmp/mysql_ram.pid # Pid file for the mysql server
# Create mysql db in ramdisk dir
mysql_install_db --basedir="$BASE_DIR" --datadir="$DATA_DIR"
@octocat
octocat / .gitignore
Created February 27, 2014 19:38
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #