Skip to content

Instantly share code, notes, and snippets.

# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
@afa
afa / feature_macros.rb
Created November 13, 2015 10:23
Tuning capybara + capybara-webkit + database_cleaner + DeferredGarbageCollection + feature macros
# spec/support/feature_macros.rb
module FeatureMacros
extend ActiveSupport::Concern
# get current domain ("lvh.me:12345")
def domain(port = Capybara.current_session.server.try(:port) || 3000)
port &&= ":#{ port }"
"#{ DEFAULT_HOST }#{ port }"
end
@afa
afa / Gemfile
Created December 23, 2015 09:40 — forked from gvarela/Gemfile
web sockets with eventmachine and redis pub/sub
# A sample Gemfile
source "http://rubygems.org"
gem "redis"
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem "em-hiredis"
# gem "em-synchrony"
gem "em-websocket"
@afa
afa / 00_README.md
Created January 20, 2017 08:03 — forked from mikechau/00_README.md
Logging Rails 4 to Syslog, formatted w/ Logstash

Logging Rails 4 to Syslog, formatted w/ Logstash

Getting Started

Steps to get Rails 4 saving its output to Syslog via Rsyslog. This assumes you are on CentOS, but should be pretty adaptable to any other distribution. Ruby 2.0+ is also required.

  1. Add the gems lograge and logstash-event to your Gemfile. Feel free to remove from production if you'd like to test it in development as well or something.
  2. Update production.rb with the lograge settings and set the logger to Syslog::Logger.
  3. Add the conf files to /etc/rsyslog.d/. /etc/rsyslog.conf should have $IncludeConfig /etc/rsyslog.d/*.conf enabled, so it will load any additional configs from /etc/rsyslog.conf.
@afa
afa / game.rb
Created May 19, 2017 12:45
celluloid game
class Game
include Celluloid
include Celluloid::IO
include Celluloid::Internals::Logger
include Celluloid::Notifications
extend Forwardable
finalizer :finalizer
def_delegators :int_state, :stage, :step, :total_steps, :step_status, :statements, :setting
attr_accessor :name, :online
@afa
afa / capybara_cheat_sheet.md
Created June 29, 2017 17:20 — forked from WaKeMaTTa/capybara_cheat_sheet.md
Capybara - Cheat Sheet

Navigating

visit("/projects")
visit(post_comments_path(post))

Clicking links and buttons

@afa
afa / rescue-from-git-push-force.md
Created August 4, 2017 13:06 — forked from Envek/rescue-from-git-push-force.md
Откат ошибочной команды git push --force

Откат ошибочной команды git push --force

Иногда при работе с несколькими удалёнными репозиториями в git, может произойти страшное: git push --force в не тот remote и/или не в ту ветку.

Такое может случиться, например, если вы используете [Deis], в котором деплой запускается при git push нужного коммита в сборщик, когда при отладке деплоя после очередного git commit --amend по запарке вместо git push deis master --force делается просто git push --force. Упс.

Как результат, последние коммиты коллег безвозвратно потеряны, и вы чувствуете неотвратимость их ярости…

Но это git, а значит всё можно починить!

@afa
afa / factory_doctor.rb
Created August 8, 2017 15:39 — forked from palkan/factory_doctor.rb
FactoryDoc: detect useless data generation in tests
module FactoryGirl
module Doctor
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
end
@afa
afa / Gemfile
Created August 8, 2017 15:40 — forked from palkan/Gemfile
FactoryProf: profiler for your FactoryGirl
# if you want to render flamegraphs
gem "stackprof", require: false # required by flamegraph
gem "flamegraph", require: false
@afa
afa / coffee-to-es6.md
Created November 15, 2017 23:23 — forked from kvz/coffee-to-es6.md
Going from CoffeeScript to ES6

These are the steps I took to change a modest project from CoffeeScript to ES6.

My ~2000LoC project took me around 6 hours to port, but I sunk 3 hours into a stupid mistake, and 2 into figuring out these steps, so with these steps & warnings at your disposal already, you should be able to do bigger projects in considerably less time.

Automatic tools only take you so far, there will be some manual fixing. Sometimes the generated code clearly doesn't look like a human wrote it, and sometimes there are bugs.

In this last case, when porting software trips over a particular bit of CoffeeScript, comment this bit out, and try transpiling the file again. If this is successfull, you'll see the commented CoffeeScript inside the JS, and you can port that bit yourself.

Okay let's dive right in!