Skip to content

Instantly share code, notes, and snippets.

@sparrovv
sparrovv / uuid_to_bindata.rb
Created January 31, 2017 21:20
Convert json files that include $uuid node
#!/usr/bin/env ruby
require 'json'
def uuid_to_hex(uuid)
hex = uuid.gsub(/[{}-]/, "")
msb = hex[0,16]
lsb = hex[16,16]
msb = msb[14, 2] + msb[12, 2] + msb[10, 2] + msb[8, 2] + msb[6, 2] + msb[4, 2] + msb[2, 2] + msb[0, 2]
lsb = lsb[14, 2] + lsb[12, 2] + lsb[10, 2] + lsb[8, 2] + lsb[6, 2] + lsb[4, 2] + lsb[2, 2] + lsb[0, 2]
@sparrovv
sparrovv / beans.rb
Created March 13, 2016 10:55
the-jellybean-problem
# http://waitbutwhy.com/2016/03/the-jellybean-problem.html
Bean = Struct.new(:state)
state_of_the_one_i_picked_at_the_beginning = []
state_of_the_last_one_on_the_stump = []
1000.times do
# create beans
bean1 = Bean.new :dead
@sparrovv
sparrovv / bash.sh
Created August 17, 2015 13:29
ELB log parsing and jq filtering
# brew install jq
cat elb-logs.log | elb_parser.rb | jq 'select(.elb_status_code != "200")'
cat elb-logs.log | elb_parser.rb | jq '.'
@sparrovv
sparrovv / keybase.md
Created June 14, 2015 18:48
keybase.md

Keybase proof

I hereby claim:

  • I am sparrovv on github.
  • I am sparrovv (https://keybase.io/sparrovv) on keybase.
  • I have a public key whose fingerprint is 0FCB D37F 74E3 464B CBC4 E842 2675 4E59 47A0 C4BD

To claim this, I am signing this object:

@sparrovv
sparrovv / wifimonitor.rb
Created March 12, 2015 21:49
Restart osx airport if no connection to the internet
#!/usr/bin/env ruby
# gem install net-ping
# Usage
# sudo ./wifimonitor.rb
require 'net/ping'
require 'logger'

Keybase proof

I hereby claim:

  • I am sparrovv on github.
  • I am sparrovv (https://keybase.io/sparrovv) on keybase.
  • I have a public key whose fingerprint is 1A34 62C1 D773 504B 260A 436D F963 E58F 35FE 89A4

To claim this, I am signing this object:

@sparrovv
sparrovv / gist:5138869
Last active December 14, 2015 19:48
Ensure no invalid UTF8 chars in user data
class UTF8Validator
class InvalidUTF8Character < Exception; end
VALIDATE_ENV_KEYS = [
"QUERY_STRING",
"REQUEST_PATH",
"REQUEST_URI",
"rack.request.form_vars" # POST data
]
@sparrovv
sparrovv / retryable
Created December 4, 2011 20:16
retry code if case of some specific exception
# I don't remember where I found it but it's useful in case of errors like: Net::HTTP::Persistent::Error: too many connection resets...
module Kernel
# Options
# =======
# * :tries Number of retries to perform. Defaults to 1.
# Note this means it actually tries 2 times!
# * :on - The Exception on which a retry will be performed. Defaults to
# Exception, which retries on any Exception.
# * :delay - Delay in seconds before the next try (optional)
#
@sparrovv
sparrovv / js asspect
Created September 5, 2011 07:45
Simple js asspects
var Asspect = (function(){
var add = function(object, functionName, opts){
object = object || window;
var originalFunction = object[functionName];
// check if function exists
object[functionName] = function(){
@sparrovv
sparrovv / ruby_servlet_example
Created October 21, 2010 21:01
Simple Ruby Web Servlet done with Webrick
# Example of simple webservlet, that can run on your computer and be triggered by http
require 'webrick'
class Simple < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
status, content_type, body = do_some_stuff(request)
#system('touch ~/yeah.file')
response.status = status
response['Content-Type'] = content_type