Skip to content

Instantly share code, notes, and snippets.

@morhekil
morhekil / main.go
Created August 10, 2014 11:20
Go kata to generate random strings, like promotional codes. See http://speakmy.name/2014/08/10/go-kata-generating-random-strings/ for details
package main
import (
"errors"
"fmt"
"morhekil/training/randstr/generator"
"os"
"strconv"
)
@morhekil
morhekil / nginx.conf
Created August 7, 2014 12:53
data sink for nginx
http {
log_format datasink $request_body;
}
server {
listen 1.2.3.4;
location /datasink {
return 200;
}
@morhekil
morhekil / swifter.rb
Created June 26, 2014 01:20
Multi-process stress load tester
require 'rubygems'
require 'bundler/setup'
require 'paperclip'
require 'openstack_bridge'
require 'dotenv'
Dotenv.load
$:.unshift File.dirname(__FILE__)
$:.unshift File.join(File.dirname(__FILE__), '..')
@morhekil
morhekil / spec_support_restful_ohm_resource.rb
Last active August 29, 2015 14:02
Shared examples spec'ing JSON API of a RESTful model backed by Ohm (Redis), for RSpec 3
# Shared examples take a model class as parameters, and expect:
# 1. ``create_attrs`` and ``update_attrs`` to be available in the context.
# 2. ``user`` method to be available in the context, representing currently logged in user.
# 3. Factory to be defined for the model, and ``build`` method to be included into examples.
#
# EXAMPLE
# -------
#
# 1. factories.rb:
# FactoryGirl.define do
@morhekil
morhekil / grape_entity_matcher.rb
Created June 22, 2014 06:00
custom RSpec 3 matcher for Grape Entities
# Custom RSpec 3 matcher to easily test validity of Grape API responses based on Grape::Entity serializers.
# It is assumed that all entities are defined as nested classes, which is the recommended approach, see
# the last example at https://github.com/intridea/grape#grape-entities
#
# HOW TO USE
# ----------
#
# 1. Require this file in your test environment.
#
# 2. To verify that a given JSON hash is the correct representation of a single model:
@morhekil
morhekil / .tmux.conf
Created April 1, 2014 08:40
vroom and tmux setup to to quickly zoom rspec's pane and put it into copy mode.
# quick zoom of another pane, with a given title ("target" in this example)
bind-key k run "~/bin/tmux-zoom-pane target"
@morhekil
morhekil / 0README.md
Last active August 29, 2015 13:56
Gruntfile and server example for Grunt+Livereload+Express/Socket.io+Static app setup.

What

Example of a gruntfile and Express-based server skeleton for Grunt+Livereload+Express/Socket.io+static app setup.

How

main.js goes into @server/main.js@, with its views set up to be found under @server/views@, and a static app (say, Backbone-based one) goes into @app/@.

@morhekil
morhekil / json_file_gz.rb
Last active April 17, 2017 23:01
json_file_gz codec for Logstash, to handle gzipped json files handled to it as file names in the input stream. Details: http://speakmy.name/2014/01/13/gzipped-json-files-and-logstash/
# encoding: utf-8
require 'logstash/codecs/base'
class LogStash::Codecs::JsonFileGz < LogStash::Codecs::Base
config_name 'json_file_gz'
milestone 1
public
def register
require 'zlib'
@morhekil
morhekil / rsync-incremental-backup.sh
Last active June 26, 2020 16:18
Shell script to handle incremental data backups with rsync. Optimised to handle large number of infrequently changing files, by using hard links to save on used disk space. For more details - http://localhost:4000/2014/01/12/automatic-backups-with-ruby-and-linux-shell-part-3/
#!/bin/bash
# Rsync based file backup script, with hard-linking enabled.
#
# Runtime options:
# -n - dry-run; do nothing, just display what is going to happen on a real run
# -v - verbose output; print out what is being backed up
#
# set to your rsync location
#!/usr/bin/env ruby
module ClassMixin
def ping
puts 'pong'
end
end
module InstanceMixin