Skip to content

Instantly share code, notes, and snippets.

@shanna
shanna / gist:6d2a6c91222ba4fa81a4
Created December 17, 2014 03:02
printf uint64_t binary.
// Has the advantage of not needing a temp buffer.
#define BINARY_8_FORMAT \
"%d%d%d%d%d%d%d%d"
#define BINARY_8_PARAMS(byte) \
(byte & 0x80 ? 1 : 0), \
(byte & 0x40 ? 1 : 0), \
(byte & 0x20 ? 1 : 0), \
(byte & 0x10 ? 1 : 0), \
(byte & 0x08 ? 1 : 0), \
@shanna
shanna / README.md
Last active August 29, 2015 14:19
BuildKite Systemd Target

BuildKite Systemd Target

Debian Jessie buildkite agent when networking is up.

/etc/systemd/system/buildkite-agent.service

module Blah
include DataMapper::SphinxResource
property :id, Serial
property :name, String
# No dm-is-searchable, we need to order by :weight.
def self.my_search(search_options = {}, options = {})
docs = repository(:search){self.all(search_options)}
ids = docs.map{|doc| doc[:id]}
results = self.all(options.merge(:id => ids))
DataMapper.setup(:default, options = {}) # Your :default repo.
DataMapper.setup(:search, :adapter => 'sphinx')
class Item
include DataMapper::Resource
# .. normal properties and such for :default
# This property is a computed field that only exists in :search aka your sphinx index{}.
# They do not have to exist in :default.
repository(:search) do
module Blah
include DataMapper::SphinxResource
# repository(:default) properties
# repository(:search) sphinx properties
#--
# Pagination provided by dm-is-paginated
# http://github.com/lholden/dm-is-paginated/tree
# You could just as easily brew the pagination yourself, it's very simple:
# http://github.com/lholden/dm-is-paginated/blob/670509c97d6fe298d2314dafbe1db91eff759ee5/lib/dm-is-paginated/is/paginated.rb
#!/usr/bin/env ruby
log = IO.popen("varnishlog -o")
loop do
Signal.trap('INT'){ exit 0}
while line = log.readline
next unless line =~ /^\s+\d+\s+([A-Z]\w+)\s+[-cb]\s(.*)$/
head, line = $1, $2
colour = case head
diff --git a/lib/sinatra_warden/sinatra.rb b/lib/sinatra_warden/sinatra.rb
index a6bf5e3..652bdd6 100644
--- a/lib/sinatra_warden/sinatra.rb
+++ b/lib/sinatra_warden/sinatra.rb
@@ -35,7 +35,10 @@ module Sinatra
def self.registered(app)
app.helpers Warden::Helpers
-
+ app.use Warden::Manager do |manager|
<?php
# Mysql
#
# require_once('mysql.php');
# $db = new Mysql(dbname, server, user, pass);
# $sth = $db->query('select * from blah where name = ? limit 1', 'fred') || die($db->error());
# while ($row = mysql_fetch_assoc($sth))
# ...
#
require 'benchmark'
def each_acc list
foos = []
list.each do |letter|
foos << letter.to_i
end
foos
end
#--
# TODO: Ask about this monkey patch or alternatively I was thinking repository.create_query(*args) which would in turn
# call the same method on the adapter. The command stuff in data objects works the same way so I don't see a good
# argument against it other than the extra dispatch would be slightly slower.
module DataMapper
class Query
extend Chainable
chainable do
def self.new(*args, &block)