Skip to content

Instantly share code, notes, and snippets.

import _ "net/http/pprof"
// If the app is not running an http server, one needs to start one:
go func() {
log.Println(http.ListenAndServe("localhost:8000", nil))
}()
// Or else/then its just point the browser to:
// http://ip:port/debug/pprof/</code>
package main
import "fmt"
type Person struct {
Name string
age int // not Exported
}
func main() {
@pedromg
pedromg / gist:629d8309f4c8c4a39bc9
Last active August 29, 2015 14:21
Stripe Charge for Google AppEngine
package payment
import (
"fmt"
"appengine"
"appengine/urlfetch"
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/currency"
#!/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.
#
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')
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
#! /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:
@pedromg
pedromg / webapp.rb
Created November 17, 2010 12:53 — forked from igrigorik/webapp.rb
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
@pedromg
pedromg / gist:1090142
Created July 18, 2011 17:47
DataMapper update_or_create
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
@pedromg
pedromg / .bash_prompt
Created October 26, 2011 20:26 — forked from melo/.bash_prompt
uber git PS1
#!/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: