Skip to content

Instantly share code, notes, and snippets.

View loz's full-sized avatar

Jonathan Lozinski loz

  • Edinburgh, Glasgow
View GitHub Profile
@loz
loz / logstash.conf
Last active August 29, 2015 14:17
Docker ELK
docker run -d -p 9200:9200 \
--name elasticsearch \
-p 9300:9300 \
-v /data:/data dockerfile/elasticsearch \
/elasticsearch/bin/elasticsearch -Des.config=/data/elasticsearch.yml
docker run --name kibana \
-d -p 8080:8080 \
--link elasticsearch:docker.mrloz.xyz \
clusterhq/kibana
@loz
loz / manual.yaml
Created January 2, 2015 12:44
Drydock manual build example
name: "Drydock"
steps:
checkout:
image: git-checkout
# Running image will bind mount /root/.ssh credentials
ssh: true
# CO -> Manual Build Script
manual-build:
dependencies:
@loz
loz / gist:9072117
Last active August 29, 2015 13:56
Exploring speedier finds and querySelectorAll craziness
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
</head>
<body>
<div id="top"></div>
<div id="results"></div>
<script>
var $domElements = $("<div style='height:400px; overflow:scroll;'></div>");
for(var a = 1; a <= 10; a++) {
@loz
loz / gist:2940508
Created June 16, 2012 08:24
Setting Session in Sinatra/Rspec
#Took me ages to work this out:
def setup_session(session = {})
Rack::Session::Abstract::SessionHash.stub(:new).and_return(session)
end
#then in your tests
before :each do
setup_session :user_id => User.first.id
get '/user_required'
@loz
loz / gist:2473927
Created April 23, 2012 21:17
Generate gems.tags from your bundle in a project
#!/usr/bin/env ruby
require 'bundler'
require 'bundler/runtime'
puts 'Building gems.tags from bundle'
outpath = 'gems.tags'
begin
runtime = ::Bundler::Runtime.new Dir.pwd, ::Bundler.definition
paths = runtime.specs.map(&:full_gem_path).join(' ').strip
File.open('hello.rb', 'wb') {|f| f.write 'class Hello; end' }
x = Module.new
file = File.open('hello.rb') {|f| f.read }
x.module_eval(file)
x::Hello
#Patch Module:
class Module
public
def load_from_file(file)
@loz
loz / gist:907900
Created April 7, 2011 14:44
Extend Example with XTEND not extend
class Object
def self.xtend(klass)
self.class.send(:include, klass)
end
end
module AccessorWrapper
def self.included(base)
#base.extend ClassMethods
@loz
loz / gist:907868
Created April 7, 2011 14:32
Extend Exercise
module AccessorWrapper
def self.included(base)
base.extend ClassMethods
end
def self.sneaky_logger(klass, accessor)
@logged_stuff ||= {}
@logged_stuff[klass] ||= []
@logged_stuff[klass] << accessor
Ruby is awesome!:
if Date.today.wednesday?
else
end
@loz
loz / gist:907811
Created April 7, 2011 13:53
Scottish Ruby Conference - Cheaty 'new' method
class Object
def new(klass, *args)
klass.new(*args)
end
end
x = new String
p x
p new Array