Skip to content

Instantly share code, notes, and snippets.

View 6temes's full-sized avatar
😏
I have a plan

Daniel 6temes

😏
I have a plan
View GitHub Profile
@mpeteuil
mpeteuil / rubocop_pre_commit_hook
Created August 3, 2013 17:44
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@mkyed
mkyed / dj.rb
Created September 19, 2013 09:41
Look for already existing Delayed::Job
class Delayed::Job
scope :waiting, lambda{where(failed_at: nil).where(locked_at: nil)}
def self.include?(object, method_name = nil, queue = :default)
object_class = object.respond_to?(:id) ? object.class : object
object_id = object.respond_to?(:id) && object.id
waiting.where(queue: queue).detect do |job|
o = job.payload_object.object
m = method_name.present? ? job.payload_object.method_name : nil
o_class = o.respond_to?(:id) ? o.class : o
@nabucosound
nabucosound / heroku_env_copy.sh
Created December 30, 2013 12:40
Script to copy environment variables from an existing heroku app to another one
#!/bin/bash
# Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/
set -e
sourceApp="$1"
targetApp="$2"
while read key value; do
@staltz
staltz / introrx.md
Last active July 15, 2024 15:43
The introduction to Reactive Programming you've been missing

The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.

Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.

For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.

Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob

@kule
kule / mini_rspec.rb
Created September 11, 2018 09:37
Simplified example of how rspec works
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'colorize'
end
class MatcherInterface
def initialize(some_object)
@some_object = some_object
@davidcharlesweber
davidcharlesweber / ruby-jmeter test plan as rake file
Last active April 28, 2020 05:56
Gist for ruby-jmeter that will happily down a production rails app for you. Assumes that the application is using devise. Change thread count, duration and rampup to your needs. This will sign in as two different types of uses as a sample. Modify for your needs.
desc 'Generate and execute jmeter test plan'
task :generate_jmeter_plan do |t, args|
require 'ruby-jmeter'
generate_report
end
def generate_report
uri = URI('https://yourapp.com')
domain = uri.host
test do