Skip to content

Instantly share code, notes, and snippets.

View freegenie's full-sized avatar

Fabrizio Regini freegenie

View GitHub Profile
@mperham
mperham / gist:7d763bdc42465caf17c7
Last active August 29, 2015 14:02
Rule execution

I want to build a system which uses rules. These rules will change hourly (i.e. "this rule is effective from 2pm to 6pm"). The rules must support arbitrarily complex logic on just 2-3 pre-defined variables and result in a boolean:

item.a > 10 && item.b == 0 || item.category == FOOTWEAR

These rules will be executed hundreds of times per second so I can't afford the overhead of plain old eval. I want to reload the current effective ruleset from the database hourly, precompile each rule's logic string and execute it via the quickest method possible. It might look something like this:

class Rule
@bigcurl
bigcurl / sha_stream.rb
Created May 16, 2011 21:27
A simple goliath API that returns the sha1 hash of an uploaded file.
#!/usr/bin/env ruby
# encoding: utf-8
require 'goliath'
require 'digest/sha1'
class ShaStream < Goliath::API
def on_headers(env, headers)
env['async-digest'] = Digest::SHA1.new # SHA1 or MD5
str = env['CONTENT_TYPE'].match(/multipart\/form-data.*boundary\=?([^"\;,]+)?/)
@vjt
vjt / monitor.sh
Created February 23, 2012 17:19
Web server tmux monitoring session
#!/bin/sh
#
# Starts a multiplexed terminal session with tmux running monitoring software.
# Requires dstat, htop and grc. The apache configuration for grc can be found
# here: https://gist.github.com/1885569
#
# My .tmux.conf is here instead: https://gist.github.com/1886016#file_3_tmux.conf
#
# tmux 1.7 or later recommended.
#
@paulogaspar7
paulogaspar7 / www.rb
Created August 30, 2012 14:40 — forked from pda/www.rb
www: Serve the current directory via HTTP.
#!/usr/bin/env ruby
# Serve the current directory via HTTP.
# Like Python's SimpleHTTPServer, but with no-cache headers.
# Default port 8000, specify alternate port as first parameter:
# www 3000
# sudo www 80 # (probably a bad idea)
# Inspired by http://chrismdp.github.com/2011/12/cache-busting-ruby-http-server/
@freegenie
freegenie / unicorn.conf.rb
Created December 13, 2012 00:14
Unicorn after_fork block to have Rails write logs to a separare file for each worker.
after_fork do |server, worker|
log_path = Rails.root.join('log',"#{Rails.env}.#{worker.nr}.log")
new_logger = Logger.new(log_path)
new_logger.level = Logger::INFO
Rails.logger.flush
Rails.logger.close
Rails.logger = Rails.application.config.logger = ActiveSupport::TaggedLogging.new(new_logger)
module Devise
module Orm
module MongoMapper
module Hook
def devise_modules_hook!
extend Schema
include Compatibility
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }
@yagitoshiro
yagitoshiro / push_notifications.js
Last active August 13, 2016 17:29
apple push notification sample (Titanium Mobile)
//////////////////////push_notifications.js///////////////////////
var apns = function(){
var pref = require('preferences').preferences;
Titanium.Network.registerForPushNotifications({
types: [
Titanium.Network.NOTIFICATION_TYPE_BADGE,
Titanium.Network.NOTIFICATION_TYPE_ALERT
],
success:function(e)
@matschaffer
matschaffer / create_data_bag.rb
Created June 8, 2012 15:30
Creating local encrypted data bags
require 'rubygems'
require 'chef/encrypted_data_bag_item'
secret = Chef::EncryptedDataBagItem.load_secret('data_bag_key')
data = {"id" => "mysql", "root" => "some secret password"}
encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(data, secret)
FileUtils.mkpath('data_bags/passwords')
File.open('data_bags/passwords/mysql.json', 'w') do |f|
f.print encrypted_data.to_json
@ryanb
ryanb / favorite_gems.md
Created March 4, 2011 17:31
A list of my favorite gems for various tasks.
@rwdaigle
rwdaigle / bundle.pem
Created May 2, 2013 16:44
Comodo SSL certificate chain. Last updated May 2, 2013
-----BEGIN CERTIFICATE-----
MIIFAzCCA+ugAwIBAgIQGLLLuqME8aAPwfLzJkYqSjANBgkqhkiG9w0BAQUFADCB
gTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxJzAlBgNV
BAMTHkNPTU9ETyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjEyMDEwMDAw
MDBaFw0xOTEyMzEyMzU5NTlaMHIxCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVh
dGVyIE1hbmNoZXN0ZXIxEDAOBgNVBAcTB1NhbGZvcmQxGjAYBgNVBAoTEUNPTU9E
TyBDQSBMaW1pdGVkMRgwFgYDVQQDEw9Fc3NlbnRpYWxTU0wgQ0EwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCt8AiwcsargxIxF3CJhakgEtSYau2A1NHf
5I5ZLdOWIY120j8YC0YZYwvHIPPlC92AGvFaoL0dds23Izp0XmEbdaqb1IX04XiR