Skip to content

Instantly share code, notes, and snippets.

@jrgns
jrgns / setup-ubuntu.sh
Last active March 25, 2017 10:34
ProxES Setup
# Dependencies / Utilities
sudo apt-get update
sudo apt-get install -y screen curl git build-essential libssl-dev
# Install RVM for Ruby
if [ ! -f ~/.rvm/scripts/rvm ]
then
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\\curl -sSL https://get.rvm.io | bash
fi
def multi_receive_encoded(encoded_events)
bytes = 0
entries = []
# Split the events into multiple batches to ensure that no single batch
# exceeds `@message_max_size` bytes.
encoded_events.each_with_index do |encoded_event, index|
event, encoded = encoded_event
if encoded.bytesize > @message_max_size
@jrgns
jrgns / ansible-play.rb
Last active March 22, 2018 23:17
Run Ansible from Slack Ruby Bot (https://github.com/slack-ruby/slack-ruby-bot)
# deploybot/commands/ansible-play.rb
module Deploybot
module Commands
class AnsiblePlay < SlackRubyBot::Commands::Base
class AnsibleRunner
attr_reader :playbook
def initialize(playbook)
@playbook = playbook
end
@jrgns
jrgns / slack_to_elasticsearch.rb
Created July 28, 2016 11:08
Simple import of Slack export into Elasticsearch
require 'date'
require 'json'
require 'logger'
require 'elasticsearch'
class SlackToElasticsearch
attr_reader :folder
def initialize(folder)
@folder = folder
@jrgns
jrgns / elasticsearch_indices.rb
Last active April 7, 2016 08:50
Convert feedback from Elasticsearch's /_cat/indices endpoint to a Ruby hash
def indices
client.cat.indices.split("\n").map do |line|
line = Hash[*[
:health,
:state,
:index,
:primaries ,
:replicas,
:count,
:deleted,
@jrgns
jrgns / import_guardian.rb
Last active August 29, 2015 14:26
Import The Guardian articles into Elasticsearch
# encoding: UTF-8
require 'elasticsearch'
require 'rest-client'
require 'json'
require 'pp'
require 'hashie'
# Default options
def params
{
require 'dotenv'
require 'win32/service'
require 'logger'
Dotenv.load
include Win32
LOGGER = Logger.new(ENV['LOG_FILE'] || STDOUT)
LOGGER.level = Logger::WARN
### Keybase proof
I hereby claim:
* I am jrgns on github.
* I am jrgns (https://keybase.io/jrgns) on keybase.
* I have a public key whose fingerprint is 509D 730E 6927 2855 1A7C B932 8158 85AA 28F9 EF79
To claim this, I am signing this object:
@jrgns
jrgns / gist:acc16946ec73102c6dbe
Created June 12, 2014 04:05
OAuth2 Auth Error
Started GET "/search" for 127.0.0.1 at 2014-06-11 19:20:08 +0000
ActiveRecord::SchemaMigration Load (5.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
AccessToken Load (2.6ms) SELECT "access_tokens".* FROM "access_tokens" WHERE "access_tokens"."token" = 'O2_A6iGept7Ibgxd80rWUIV7g5txf_E9h90YNUFmb9BSujoIXQPAS24fLMAGIjHBTBgefcIv21GsokkTGCdfyA' LIMIT 1
Client Load (1.9ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1 [["id", 1]]
AccessToken Exists (2.0ms) SELECT 1 AS one FROM "access_tokens" WHERE ("access_tokens"."token" = 'O2_A6iGept7Ibgxd80rWUIV7g5txf_E9h90YNUFmb9BSujoIXQPAS24fLMAGIjHBTBgefcIv21GsokkTGCdfyA' AND "access_tokens"."id" != 4) LIMIT 1
Processing by SearchController#index as */*
AccessToken Load (5.4ms) SELECT "access_tokens".* FROM "access_tokens" WHERE "access_tokens"."token" = 4 LIMIT 1
PG::UndefinedFunction: ERROR: operator does not exist: character varying = integer
LINE 1: ...OM "access_tokens" WHERE "access_tokens"."token" = 4 LIMIT .