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
Warden::Manager.serialize_into_session{|user| user.id } | |
Warden::Manager.serialize_from_session{|id| User.get(id) } | |
Warden::Manager.before_failure do |env,opts| | |
# Sinatra is very sensitive to the request method | |
# since authentication could fail on any type of method, we need | |
# to set it for the failure app so it is routed to the correct block | |
env['REQUEST_METHOD'] = "POST" | |
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
# NOTE: this is a code spike, and the following code will probably | |
# not make it into dm-core in it's current form. I wanted to see if it | |
# were possible to use a topographical sort to ensure parents were | |
# saved before children, before/after filters were fired in the correct | |
# order, and foreign keys set before children are saved, but after parents | |
# are saved. | |
# The hooks should fire in the following order: | |
# https://gist.github.com/6666d2818b14296a28ab |
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 -Ku | |
# encoding: utf-8 | |
# The idea with this code spike is to parse some code that has YARD | |
# documentation, and then wrap the methods at runtime to ensure that | |
# they match the behavior specified in the docs. | |
# | |
# This code will test the input, output and exceptions for every | |
# documented method. It will also test the provided block's input |
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 'minitest/mock' | |
require 'minitest/unit' | |
require 'date' | |
MiniTest::Unit.autorun | |
class TestMailPurge < MiniTest::Unit::TestCase | |
class MailPurge | |
def initialize(imap) | |
@imap = imap |
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
// Target API: | |
// | |
// var s = require('net').createStream(25, 'smtp.example.com'); | |
// s.on('connect', function() { | |
// require('starttls')(s, options, function() { | |
// if (!s.authorized) { | |
// s.destroy(); | |
// return; | |
// } | |
// |
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
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :username, String, :required => true, :unique => true | |
property :address_street_address, String | |
property :address_location, String | |
property :address_subdivision, String | |
property :address_country, 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
import logging | |
from math import exp | |
from random import random | |
from time import sleep | |
from time import time | |
from uuid import uuid1 | |
from redis.exceptions import WatchError |
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
# Yields the given models wrapped in Loader::Table objects that can be | |
# used to write SQL. The block should return an array with the SQL as | |
# the first element, and variable substitutions as the rest. | |
# | |
# Example | |
# using_sql(Article) {|a| | |
# ["SELECT #{a.*} FROM #{a} WHERE #{a.id} = ?", 1] | |
# } | |
def using_sql(*models) | |
opts = models.extract_options! |
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
class QueryTraceLogger | |
def initialize(logger) | |
@logger = logger | |
end | |
def method_missing(method_name, *args) | |
if method_name == :debug | |
if args.first =~ /SQL/ | |
Rails.logger.debug "" | |
Rails.backtrace_cleaner.clean(caller).each do |line| |
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
-- Retrieve descendants | |
-- ==================== | |
-- retrieve descendants of #4 | |
SELECT c.* | |
FROM Comments AS c | |
JOIN TreePaths AS t ON c.comment_id = t.descendant | |
WHERE t.ancestor = 4; | |
-- Retrieve ancestors |
OlderNewer