Skip to content

Instantly share code, notes, and snippets.

@chipairon
chipairon / Results.md
Created June 22, 2017 08:27
Comparing alternatives for encoding lookup

Results

ruby unique_vs_repeated_benchmark.rb 
Warming up --------------------------------------
unique table for both lower and upper case
                       222.550k i/100ms
unique table with custom upcase
                       290.924k i/100ms
each case has its own entry
defmodule Crasher do
require Logger
def start do
{:ok, _agent} = Agent.start_link
fn -> %{aa: 1, bb: 2, cc: 0, dd: 3} end,
name: :crasher_agent
end
defmodule Crasher do
def start do
{:ok, _agent} = Agent.start_link
fn -> %{aa: 1, bb: 2, cc: 0, dd: 3} end,
name: :crasher_agent
end
def show do
Agent.get :crasher_agent, fn x -> x end
@chipairon
chipairon / crasher.ex
Last active September 12, 2015 14:36
Do not crash the agent!
defmodule Crasher do
require Logger
def start do
{:ok, _agent} = Agent.start_link fn -> %{aa: 1, bb: 2, cc: 0, dd: 3} end, name: :crasher_agent
end
def show do
Agent.get :crasher_agent, fn x -> x end
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'sqlite3'
GEMFILE
system 'bundle'

Simplistic Full-Text Search With Redis's Sorted Sets

Howto

git clone git://gist.github.com/923934.git redisearch

cd redisearch
# Outputs this at warn log level:
# 1.2.3.4 GET /path 200 OK BlahController#action HTML 938.2 (DB 11.8, View 719.7) {params} {optional params from flash[:log]}
#
# Save as config/initializers/oneline_detailed_logging.rb. Consider
# decreasing the log level from "info" to "warn" (in production.rb) so
# the one-line log message replaces the standard request logs.
# override process_action to add 2 things to the payload:
# - remote IP
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
require 'openssl'
require 'digest/sha1'
require 'base64'
require 'json'
def go_demo!
key = Digest::SHA1.hexdigest("clave1")[0..15] # 16bytes => 128bits
iv = 'clave2 con chicha'[0..15] # 16bytes forced
data = { esto: 'es', un: 'hash', en: 'ruby' }
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<a href="http://www.google.com"> Go to Google </a>
<div> Click me to trigger custom click </div>
</body>