Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / Dockerfile
Last active August 29, 2015 14:05
Docker container for Go builds
FROM ubuntu
# Download and unpack golang archive
RUN apt-get update
RUN apt-get install -y wget git
RUN wget https://storage.googleapis.com/golang/go1.3.1.linux-amd64.tar.gz -O /tmp/golang.tar.gz
RUN tar -C /usr/local -xzf /tmp/golang.tar.gz
# Configure the environment
RUN echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile.d/go.sh
# Substitute path/version of hadoop files below
HADOOP_CLASSPATH=/usr/local/Cellar/hadoop/2.4.0/libexec/share/hadoop/yarn/test/hadoop-yarn-server-tests-2.4.0-tests.jar hadoop jar /usr/local/Cellar/hadoop/2.4.0/libexec/share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.4.0-tests.jar minicluster --nnport=8020
@morhekil
morhekil / build.sh
Created November 24, 2014 10:55
guilder - build.sh for go build service
#!/bin/bash
set -e # exit on first error
set -x
BUILD_DIR=/build/go
DIST_DIR=/dist
SRC_DIR=$BUILD_DIR/src/$PKG
source /etc/profile
@morhekil
morhekil / Makefile
Created February 24, 2015 09:09
Example of using httest (http://htt.sourceforge.net) to test availability and configuration of a set of domains
all:
./poker.htt
./casino.htt
./sports.htt