Skip to content

Instantly share code, notes, and snippets.

View LeipeLeon's full-sized avatar
🕳️

Leon Berenschot LeipeLeon

🕳️
View GitHub Profile
# run as `ruby swedish_chef.rb`
# Source: unknown, e.g. copied somewhere from the interwebs
class SwedishChef
def self.call(string)
@string = string
@string.gsub!(/an/, "un")
@string.gsub!(/An/, "Un")
@string.gsub!(/au/, "oo")
@string.gsub!(/Au/, "Oo")
# Taken from https://thoughtbot.com/blog/how-to-stub-external-services-in-tests
require 'sinatra/base'
class FakeMuxApi < Sinatra::Base
configure :production, :development do
enable :logging
end
post '/video/v1/assets' do
@LeipeLeon
LeipeLeon / controllers.application.js
Last active April 1, 2019 16:12
Ember list routes
import Ember from 'ember';
import EmberRouter from '@ember/routing/router';
import { computed } from '@ember/object';
export default Ember.Controller.extend({
appName: 'Ember Twiddle!',
myRoutes: computed('isInitialized', function(){
let owner = Ember.getOwner(this);
let router = owner.lookup('router:main');
let routes = router._routerMicrolib.recognizer.names;
@LeipeLeon
LeipeLeon / spec_helper.rb
Created May 24, 2011 12:55
capture std in/out/err
def capture(*streams)
require 'stringio'
streams.map! { |stream| stream.to_s }
begin
result = StringIO.new
streams.each { |stream| eval "$#{stream} = result" }
yield
ensure
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
# In 1.9 the Time#to_s method doesn't return in the format as outlined in the pickaxe book (PDF page 747):
it "ouput of #to_s is different in 1.8 and 1.9" do
time = Time.at(1289349987)
time.strftime("%a %b %d %H:%M:%S %z %Y").should eql('Wed Nov 10 01:46:27 +0100 2010') # passes
time.to_s.should eql('Wed Nov 10 01:46:27 +0100 2010') # fails
end
# Failure/Error: time.to_s.should eql('Wed Nov 10 01:46:27 +0100 2010')
# expected "Wed Nov 10 01:46:27 +0100 2010"
module MyAccessors
@@my_accessors = []
def my_accessor var
attr_accessor var
@@my_accessors << var
end
def my_attributes
class AppServer
attr_accessor :admin_password, :port
end
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
def app_server
@app_server ||= AppServer.new
yield @app_server if block_given?
@LeipeLeon
LeipeLeon / gist:884603
Created March 24, 2011 05:01
Textmate -> preferences -> advanced -> Folder Rerences
File Pattern:
!(/\.(?!htaccess)[^/]*|(swf|mp3|jpeg|gif|png|psd|log|pdf|sql|bz2)|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$
Folder Pattern:
!.*/(\.[^/]*|public/system|server/gems|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$
<%= image_submit_tag "button_volgende_stap.gif", :title=> t('form.submit'), :onclick => "needToConfirm = false;" %>
<% content_for :page_js do %>
<script>
var needToConfirm = false;
window.onbeforeunload = confirmExit;
function confirmExit() {
if (needToConfirm) {
return "U heeft onbewaarde wijzigingen. Doorgaan?";
@LeipeLeon
LeipeLeon / find_1500.rb
Created September 23, 2010 00:49
Find tracks from the Kink1500 (http://www.kinkfm.com/kink1500) in your iTunes Library
#!/usr/bin/env ruby
#
# Tracklisting: (c) 2010 KinkFM.com and their listeners
# Code: (c) 2010 Leon Berenschot, Wendbaar.nl
#
# Find the tracks of the Kink1500 in your iTunes library
# Usage:
# - First create a playlist called "Kink 1500-2010"
# - From the commandline execute 'ruby ./find_1500.rb'
#