Skip to content

Instantly share code, notes, and snippets.

@vierarb
vierarb / Capfile
Created January 3, 2014 20:32
Capistrano 3
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
@vierarb
vierarb / speciality.rb
Created February 21, 2014 15:49
method_missing
class Speciality < ActiveRecord::Base
validates :code, presence: true
private
def method_missing(method, *args, &block)
if method.to_s =~ /^(.+)[?]$/
run_code_comparation_method($1, *args, &block)
else
super
end
@vierarb
vierarb / coach.rb
Last active August 29, 2015 14:01
Metaprogramming the metrics
# Usage:
# coach = Coach.first
# coach.sessions_count(:started_at)
# coach.coachees_count(:created_at)
# coach.sessions_sum(:price, :started_at)
class Coach < ActiveRecord::Base
include Metric
metrics_for :sessions, :coachees
@vierarb
vierarb / gist:9b1986a78d14f5dae60d
Created May 23, 2014 15:58
Polar Area chart with d3js
var width = 750;
var height = 500;
var radius = 200;
var strokeColor = "#999";
var strokeOpacity = 0.75;
var labelMargin = radius + 20;
var concentric = [];
for(var i = 1; i <= 10; i++) {
concentric.push((radius * i) / 10);
@vierarb
vierarb / redis.rb
Last active August 29, 2015 14:03
Redis Storage
$redis = Redis.new(host: 'localhost', port: 6379, db: 1)
@vierarb
vierarb / foursquare_place.rb
Last active August 29, 2015 14:04
Foursquare Places
class FoursquarePlace
include Cacheable
ATTRIBUTES = %i(pid name street city country latitude longitude icon
categories)
def initialize(attrs = {})
@connection = FoursquareConnector.new
_initialize_attributes!(attrs)
@vierarb
vierarb / .rubocop-todo.yml
Last active August 29, 2015 14:08
Rubocop config file proposal
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-02-23 19:26:33 +0100 using RuboCop version 0.29.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
Lint/Void:
Enabled: false
@vierarb
vierarb / Guardfile
Created November 29, 2014 18:03
Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
@vierarb
vierarb / Dvorak_ES.keylayout
Last active August 29, 2015 14:10
Dvorak keylayout with custom spanish disposition
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!-- Fri, 24 Feb 2006 Generated from KCHR: "Dvorak" -->
<!-- Author: Laura Paredes <laura@wearepeople.io>-->
<!--Last edited by Ukelele version 2.2.8 on 2014-12-21 at 09:58 (CET)-->
<keyboard group="0" id="16300" name="Dvorak ES" maxout="1">
<layouts>
<layout first="0" last="0" modifiers="commonModifiers" mapSet="ANSI"/>
</layouts>
<modifierMap id="commonModifiers" defaultIndex="0">
@vierarb
vierarb / Dockerfile
Created August 14, 2017 07:56
Docker configuration
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential
# for postgres
RUN apt-get install -y libpq-dev
# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev