Skip to content

Instantly share code, notes, and snippets.

View namxam's full-sized avatar

Maximilian Schulz namxam

View GitHub Profile
@namxam
namxam / log_intercetor.rb
Created February 10, 2015 14:39
Little class to help inspecting log output
# Simply put it in spec/support/log_interceptor.rb
#
# Just tag a describe or context block with ':intercept_logs'
#
require 'stringio'
require 'logger'
module LogInterceptor
def self.logger
@logger ||= ActiveSupport::TaggedLogging.new(Logger.new(output))
@namxam
namxam / application_helper.rb
Created December 5, 2014 12:42
Parameter-Übergabe
module ApplicationHelper
# Hier ist der default Wert von data ein leerer Hash
def mein_helper(input_1, data: {})
haml_tag(:picture, data: data)
end
end
@namxam
namxam / fizzbuss.exs
Last active August 29, 2015 14:09
Little fizzbuzz implementation without conditionals
# Notes for non-elixir readers
#
# In elixir, all modules and function definitions are enclosed in do … end
# One-line methods can be shortended to: ```def method_name(params), do: _method_body_
# defp defines private methods, which can only be called from within a module
#
# |> is an operator which takes the left hand side and passes it as the first parameter to the right hand side function
#
# &transform/1 passes the function as a proc. ```transform``` is the method name. ```/1``` the number of paramaters. As we
# might have multiple method implementations with the same name.
@namxam
namxam / field_names.rb
Created October 13, 2014 15:43
Extract all fields from an elastic search model mapping and returns them in a format which can be used in queries
# A small elastic search extension to retrieve a list of all field names in a
# dot notation. This way we can directly use it in ES queries.
#
# Example:
#
# # in app/models/transaction.rb
# class Transaction < ActiveRecord::Base
# include ElasticSearch::FieldNames
# end
#
# spec/support/database_cleaner.rb
#
# Set sane default for database cleaner and add a meta tag to enable database commits.
# This is important if you need to test after_commit callbacks in rails. (i.e. elasticsearch)
#
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
@namxam
namxam / Vagrantfile
Created July 16, 2014 10:17
Vagrantfile for Docker integration with coreos/etcd container
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Base image optimized for vagrant and docker
config.vm.box = 'phusion/ubuntu-14.04-amd64'
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine.
config.vm.network 'forwarded_port', guest: 4243, host: 4243 # docker
@namxam
namxam / chat_demo.ex
Last active June 11, 2016 06:36 — forked from josevalim/sample output
Simple chat demo with Elixir 0.14.1
defmodule Chat.Client do
def join(server) do
client_send server, :join
end
def say(server, message) do
client_send server, { :say, message }
end
def leave(server) do
@namxam
namxam / Vagrantfile
Created June 7, 2014 08:39
A Vagrantfile to ease the development with rails projects on mac
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Base image optimized for vagrant and docker
config.vm.box = 'phusion/ubuntu-14.04-amd64'
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine.
config.vm.network 'forwarded_port', guest: 4243, host: 4243 # docker
# Start your elastic search with elasticsearch --config=path/to/your/config
##################### Elasticsearch Configuration Example #####################
# This file contains an overview of various configuration settings,
# targeted at operations staff. Application developers should
# consult the guide at <http://elasticsearch.org/guide>.
#
# The installation procedure is covered at
# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
@namxam
namxam / template.rb
Last active August 29, 2015 14:01
ElasticSearch Template
# $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-complex.rb
# (See: 01-basic.rb, 02-pretty.rb)
append_to_file 'README.rdoc', <<-README
== [3] Expert
The `expert` template changes to a complex database schema with model relationships: article belongs
to a category, has many authors and comments.