Skip to content

Instantly share code, notes, and snippets.

@burningTyger
burningTyger / README.md
Created December 27, 2011 15:16
Mongomapper many to many associations with variable key names

If you're not familiar with Rails and ActiveRecord in general or with ActiveModel in particular then MongoMapper can be difficult to cope with at times. Even though the docs are fine and in detail some parts seem to be missing that are probably obvious for those coming from Rails. I'm not a Rails guy so I post my experience with many to many associations that might help one or the other save some precious debugging hours.

Take this code:

class User
  include MongoMapper::Document
  key :name, String, :required => true
  key :email, String

key :post_ids, Array

@burningTyger
burningTyger / remove_collection.md
Created December 27, 2011 15:59
Mongomapper remove a collection

You have a collection of objects in you MongoDB like this here:

class Student
  include MongoMapper::Document
  key :name, String, :required => true
  key :firstname, String, :required => true
  key :course, String
end

To clean up your database you can either do this:

@burningTyger
burningTyger / mm_ed_validation.md
Created January 1, 2012 21:30
MongoMapper and validation of EmbeddedDocuments

Mongomapper can use EmbeddedDocuments inside its Documents. There are some advances and disadvantages to it. This post is about validations for EmbeddedDocuments. If you have two classes like this:

class Address
	include MongoMapper::EmbeddedDocument
	key :address, String, :required => true
end

class Person
	include MongoMapper::Document

many :addresses

# as seen in time19.rb
def respond_to_missing?(method, *)
method == "succ" || super
end
def method_missing(method, *args, &block)
if method.to_s == "succ"
self +1
else
@burningTyger
burningTyger / gist:1858524
Created February 18, 2012 09:51
Git issue after replacing XCode with Command line Tools

After I uninstalled XCode via

sudo /Developer/Library/uninstall-devtools --mode=all

and reinstalled the new command line tools from apple I had a weird git error:

fatal: You don't exist. Go away!

whenever I tried to connect with a remote repository like Github or Bitbucket.

@burningTyger
burningTyger / patch.md
Created March 21, 2012 14:14
Using PATCH in Rack::Test

In case you want to use the PATCH verbin Rack::Test and you get errors when you try it with the current gem release you will have to use the git version in your Gemfile:

group :test do
  gem 'rack-test', :git => "https://github.com/brynary/rack-test.git"

While the PATCH verb has been included in a recent patch it's not yet in the gem release. Using the :git repo lets you test also PATCH routes for your rack app.

@burningTyger
burningTyger / aa_instructions.md
Created May 2, 2012 13:42 — forked from NZKoz/aa_instructions.md
Back Up All Your Gmail
  • Install getmail (aptitude install getmail4)
  • Set Up Your Imap Server (tl;dr)
  • getmail
  • ruby date_based_archive.rb ~/Maildir/.Archive
@burningTyger
burningTyger / sparkle.zsh
Created May 16, 2012 22:25
An omyzsh theme file with git and rvm features
PROMPT='$fg_bold[blue][ $fg[red]%t $fg_bold[blue]] $fg_bold[blue] [ $fg[red]%n@%m:%~$(git_prompt_info)$fg[yellow]$(rvm_prompt_info)$fg_bold[blue] ]$reset_color
$ '
# git theming
ZSH_THEME_GIT_PROMPT_PREFIX="$fg_bold[green]("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_CLEAN="✔"
ZSH_THEME_GIT_PROMPT_DIRTY="✗"
@burningTyger
burningTyger / .rn
Created June 13, 2012 07:32
Powering off a ReadyNas Drive from the command line
#use this script to turn off your ReadyNas file server from your command line without using the browser.
#Add your ReadyNas host IP, username and password and then call your script from the terminal.
#you might have to install curl which is used to contact the server.
host='readynas_ip'
user='username'
pass='password'
curl -u $user:$pass -k "https://$host/get_handler?PAGE=System&OUTER_TAB=tab_shutdown&INNER_TAB=NONE&shutdown_option1=1&command=poweroff&OPERATION=set"
@burningTyger
burningTyger / gist:3479004
Created August 26, 2012 13:05
Drupal on Openshift

#Drupal on Openshift There is an existing repo for a quick install of Drupal 7 over at https://github.com/openshift/drupal-example. This didn't really cut the deal for me because the example was Drupal 7, I needed Drupal 6 and I wasn't happy about the way it is managed codewise.

I needed this:

  • Drupal 6
  • easy updates via git
  • simple module management
  • multisite setup