Skip to content

Instantly share code, notes, and snippets.

@bgentry
bgentry / tags.rb
Created November 18, 2009 20:53
Provides a DataMapper Type for Tags (similar to Flags in dm-types). Tags are stored here in YAML form but made accessible to your app as symbols. Overrides the default 'Text' primitive of Yaml because, for my usage, 255chars is sufficient
require 'set'
module DataMapper
module Types
class Tags < Yaml
primitive String
length 255
lazy false
def self.inherited(target)
diff --git a/libavcodec/resample.c b/libavcodec/resample.c
index b008180..b4fa9e6 100644
--- a/libavcodec/resample.c
+++ b/libavcodec/resample.c
@@ -52,6 +52,17 @@ struct ReSampleContext {
unsigned buffer_size[2]; ///< sizes of allocated buffers
};
+/*
+*/
require 'dm-core'
require 'active_model'
module ActiveModel
module MassAssignmentSecurity
module Sanitizer
# Returns all attributes not denied by the authorizer.
def sanitize(attributes)
sanitized_attributes = attributes.reject do |key, value|
key_name = key.name rescue key
@bgentry
bgentry / gist:865037
Created March 10, 2011 22:11
Dir.glob_without
class Dir
def self.glob_without(pattern, regexp, directory = pwd)
chdir(directory) do
glob(pattern).reject {|i| i =~ regexp }.map {|i| File.expand_path(i) }
end
end
end
@bgentry
bgentry / 01-before.rb
Created June 20, 2011 21:50 — forked from anonymous/01-before.rb
Refactoring acts-as-taggable-on SQL queries to be more readable
def tagged_with(tags, options = {})
tag_list = ActsAsTaggableOn::Taggable::TagList.from(tags)
joins = []
conditions = []
context = options.delete(:on)
context_condition = context.blank? ? "" : sanitize_sql(["AND #{acts_as_taggable_on_tagging_model.table_name}.context = ?", context.to_s])
if options.delete(:exclude)
@bgentry
bgentry / sequel_paranoia.rb
Created November 30, 2011 03:20
Sequel Paranoia plugin (i.e. acts_as_paranoid)
module Sequel
module Plugins
# The paranoia plugin creates hooks that automatically set deleted
# timestamp fields. The field name used is configurable, and you
# can also set whether to overwrite existing deleted timestamps (false
# by default). Adapted from Timestamps plugin.
#
# Usage:
#
# # Soft deletion for all model instances using +deleted_at+
@bgentry
bgentry / domain.rb
Created November 30, 2011 23:02
updating the txid to txid_current() before all saves
class Domain < Sequel::Model
def before_save
model.dataset.filter(id: self.id).update(txid: :txid_current.sql_function)
super
end
end
@bgentry
bgentry / spdy-server.go
Created February 27, 2012 02:01
A simple SPDY server
// Based heavily on https://bitbucket.org/zombiezen/spdy, adapted for
// recent Go releases.
package main
import (
"crypto/tls"
"fmt"
"go.net/spdy"
"io"
@bgentry
bgentry / Readme.md
Created April 12, 2012 04:42
dbsqlconnfail: pq or database/sql ErrBadConn unhealthy connection reuse
$ go install
$ dbsqlconnfail

In another window:

$ curl localhost:8080/1
OK
@bgentry
bgentry / rated.go
Created October 11, 2012 23:48
Go token bucket rate limiter #golang
package main
import (
"fmt"
"time"
)
func main() {
ticker := rateLimit(4, 10)