This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# I deliberately didn't DRY /usr/local references into a variable as this | |
# script will not "just work" if you change the destination directory. However | |
# please feel free to fork it and make that possible. | |
# | |
# If you do fork ensure you add a comment here that explains what the changes | |
# are intended to do and how well you tested them. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'dm-core' | |
require 'dm-postgres-adapter' | |
require 'adapter.rb' # local; patched | |
require 'comparison.rb' # local; patched | |
require 'symbol.rb' | |
#require 'dm-migrations' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'postgres://user:password@localhost/database') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataMapper | |
module Model | |
# update_or_create method: finds and updates, or creates; | |
# merger is a boolean that determines if the conditions are merged with the attributes upon create; | |
# merge = true => merges conditions to attributes and passes the merge to the create method | |
# merge = false => only attributes are passed into the create method | |
def update_or_create(conditions = {}, attributes = {}, merger = true) | |
(first(conditions) && first(conditions).update(attributes)) || create(merger ? (conditions.merge(attributes)) : attributes ) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
## | |
# == remember: | |
# * insert your login and password at Line 100, and save this file. | |
# * of couse, be very carefull if you send this to a friend... REMOVE your credentials first! | |
# * if you are using Google Hosted for your Domain (Google Apps), your_login is something like: me@mydomain.com | |
# * example: go = GoGmail.new($*[0], 'imap.gmail.com', 993, $*[1], 'tree@forest.org', 'littlebird', $*[2]) | |
# | |
# == usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if !has('ruby') | |
finish | |
endif | |
" Vim syntax functions | |
" Language: wordpress_vim | |
" Maintainer: pedro mg <pedro.mota [at] gmail.com> | |
" Version: 1.1 | |
" Last Change: 2008 Apr 04 | |
" Remark: Simple functions for vim blogging bundle in ruby. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DataMapper | |
module Model | |
# update_or_create method: finds and updates, or creates; | |
# -upon create, returns the object | |
# -upon update, returns the object (by default, returned True) | |
# @param[Hash] Conditions hash for the search query. | |
# @param[Hash] Attributes hash with the property value for the update or creation of a new row. | |
# @param[Boolean] Merger is a boolean that determines if the conditions are merged with the attributes upon create. | |
# If true, merges conditions to attributes and passes the merge to the create method; | |
# If false, only attributes are passed into the create method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# PS1 magic | |
# | |
# Mostly copied from YUVAL KOGMAN version, added my own __git_ps1 stuff | |
# Original: http://gist.github.com/621452 | |
# | |
# See video demo of this at http://vimeo.com/15789794 | |
# | |
# To enable save as .bash_prompt in $HOME and add to .bashrc: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = "param1=1¶m2=2&offset=3" | |
unless query.empty? | |
# build an Hash based on the query string | |
# we want to build {"param1"=>"1", "param2"=>"2", "offset"=>"3"} | |
temp_params = {} | |
query.split("&").each {|v| temp_params.merge!(Hash[*v.split("=")]) unless (v.split("=").count < 2)} | |
# remove the offset parameter | |
temp_params.delete("offset") | |
# convert the Hash back to a String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
# We are not loading Active Record, nor Active Resources etc. | |
# We can do this in any app by simply replacing the rails gem | |
# by the parts we want to use. | |
gem "actionpack", "~> 3.2" | |
gem "railties", "~> 3.2" | |
gem "tzinfo" | |
# Let's use thin |
OlderNewer