Skip to content

Instantly share code, notes, and snippets.

@jamtur01
jamtur01 / riemann.config
Last active September 10, 2016 16:08
Example of Riemann index lookup a la Nagios Herald
(require 'riemann.common)
(require 'clojure.pprint)
(let [host "0.0.0.0"]
(graphite-server :host host
:port 5559)
(tcp-server :host host)
(udp-server :host host
:max-size 65000)
(repl-server :host host)
@clarkdave
clarkdave / logstash-sentry.rb
Last active May 15, 2023 11:34
(Logstash) Sentry output plugin
# The MIT License (MIT)
# Copyright (c) 2014 Dave Clark
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@ILoGM
ILoGM / migrator_monkey_patch.rb
Created April 15, 2014 12:06
This patch allows disable ddl transactions in Rails 3.2
class ActiveRecord::Migrator
def migrate(&block)
current = migrations.detect { |m| m.version == current_version }
target = migrations.detect { |m| m.version == @target_version }
if target.nil? && @target_version && @target_version > 0
raise UnknownMigrationVersionError.new(@target_version)
end
start = up? ? 0 : (migrations.index(current) || 0)
@niquola
niquola / DCI Context
Created July 10, 2013 15:47
Hangout Model Layer
class SignPendingOrdersService
def initialize(visit, user) # service context
@visit, @user = visit, user
end
def call # or execute
Order.for_visit(visit).pendings.each do |order|
order.activate!
OrderTemplate.find_or_create_template_for_order_and_record_template_usage!(order)
end
@niquola
niquola / strong_concern.rb
Created July 8, 2013 22:53
Strong Concern (explicit manage concern dependencies both ways)
# naive implementation
class TwoWayDelegate
attr :_subject
def initialize(subject)
@_subject = subject
end
def inspect
"TwoWayDelegate <#{methods.sort}>"
end
@teropa
teropa / resources.md
Last active December 4, 2020 05:42
Clojure Resources

Tutorials

var Comments = Backbone.Collection.extend({
url: function() {
return this.baseUrl + '/comments';
},
initialize: function(bootstrapData, options) {
this.baseUrl = options.baseUrl;
}
}),
Posts = Backbone.Collection.extend({
@savonarola
savonarola / benchmark.txt
Last active December 11, 2015 14:08
Отгрузка списка ~200 небольших записей такого вида: rails g scaffold Post title body:text. Работа с бд в обоих случаях заняла пренебрежимо мало
1.9.3-p194-perf, rails, 10 unicorns
>siege -r 200 -c 10 -d 0 'http://localhost:9080/posts'
** SIEGE 2.72
** Preparing 10 concurrent users for battle.
The server is now under siege.. done.
Transactions: 2000 hits
Availability: 100.00 %
Elapsed time: 117.59 secs
@solnic
solnic / rvm_remove_old.sh
Created December 4, 2012 09:34
Remove all rubies older than given date
DATE=2012-06-01
for version in `find $rvm_path/rubies/ -mindepth 1 -maxdepth 1 -type d -not -newermt $DATE | cut -d / -f 7`; do rvm remove $version; done
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base