Skip to content

Instantly share code, notes, and snippets.

package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@nerdalert
nerdalert / vim-cheatsheet.md
Last active November 8, 2023 23:38
VIM Cheatsheet

VIM Cheatsheet

Cursor movement

h - move cursor left
j - move cursor down
k - move cursor up
l - move cursor right

w - jump forwards to the start of a word

@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
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
// MIT license (c) andelf 2013
import (
"net/smtp"
"errors"
)
type loginAuth struct {
username, password string
@mwaterfall
mwaterfall / gist:953664
Created May 3, 2011 16:28
NSDate from Internet Date & Time String
//
// NSDate+InternetDateTime.h
// MWFeedParser
//
// Created by Michael Waterfall on 07/10/2010.
// Copyright 2010 Michael Waterfall. All rights reserved.
//
#import <Foundation/Foundation.h>
@jasonroelofs
jasonroelofs / Timings.txt
Created November 29, 2012 18:23
Using Go for embarrassingly parallel scripts
] wc -l domains.txt
783 domains.txt
] time go run domain_lookup_parallel.go
real 0m5.743s
user 0m0.359s
sys 0m0.355s
] time go run domain_lookup_sequential.go
@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
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
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')
@zgiber
zgiber / gist:6adf46b565cd0099e24b
Created January 16, 2015 21:39
Filter a slice of struct based on a map with properties and values
package slicefilter
import "reflect"
import "fmt"
func Filter(src interface{}, filter map[string]interface{}, dst interface{}) error {
srcRV := reflect.ValueOf(src)
dstRV := reflect.ValueOf(dst)
if srcRV.Kind() != reflect.Slice {