Skip to content

Instantly share code, notes, and snippets.

View lwe's full-sized avatar
💭
I may be slow to respond.

Lukas Westermann lwe

💭
I may be slow to respond.
  • Zurich, Switzerland
View GitHub Profile
@lwe
lwe / unscoped.rb
Created June 13, 2012 10:37
Module which provides the ability to unscope associations
# Provides the ability to unscope associations, this solves problems described in
# http://stackoverflow.com/questions/1540645/how-to-disable-default-scope-for-a-belongs-to/11012633#11012633
#
# Examples
#
# class Document < ActiveRecord::Base
# default_scope where(deleted: false)
# end
#
# class Comment < ActiveRecord::Base
@lwe
lwe / hapi.js
Last active September 11, 2022 12:51
Server-sent-events with trial for hapi and one with a plain node.js http server.
var Hapi = require('hapi');
var stream = require('stream');
// Create a server
var server = Hapi.createServer('localhost', 8000);
// Add a route
server.route({
method: 'GET',
path: '/hello',
@lwe
lwe / brew-services.rb
Created January 5, 2011 13:13
External script for homebrew to simplify starting services via launchctl, out of the box support for any formula which implements #startup_plist.
#!/usr/bin/env ruby -w
# brew-services(1) - Easily start and stop formulas via launchctl
# ===============================================================
#
# ## SYNOPSIS
#
# [<sudo>] `brew services` `list`<br>
# [<sudo>] `brew services` `restart` <formula><br>
# [<sudo>] `brew services` `start` <formula> [<plist>]<br>

Keybase proof

I hereby claim:

  • I am lwe on github.
  • I am lwe (https://keybase.io/lwe) on keybase.
  • I have a public key ASBR3o4RHUCJWVKn-5UvI43Qry8SjTb6YzhWGhdK__YOYwo

To claim this, I am signing this object:

@lwe
lwe / example_usage.markdown
Created September 18, 2009 10:05
iPhoto-like preview batches (Video in action: http://www.vimeo.com/6639381)

in action: http://www.vimeo.com/6639381

javascript:

var pp = "/images/test/images_";
var images_p1 = [ pp + '1.jpg', pp + '2.jpg', pp + '3.jpg', pp + '4.jpg', pp + '5.jpg' ];
var images_p2 = [ pp + '6.jpg', pp + '7.jpg', pp + '8.jpg', pp + '9.jpg', pp + '10.jpg' ];

$('.preview').slideview(function(e) { return e.id == "p1" ? images_p1 : images_p2; }, { size: 75 });
@lwe
lwe / faker_ch.rb
Created August 11, 2009 11:26
Swiss-ify random data generated by faker
# make faker a bit more swiss-friendly :)
module Faker
class Company
# Add swiss suffixes like AG, GmbH etc.
def self.suffix
%w(AG GmbH und\ Söhne und\ Partner &\ Co. Gruppe LLC Inc.).rand
end
end
@lwe
lwe / brew-rebase.sh
Created July 28, 2010 07:15
Replacement for `brew update` which uses rebase.
#!/bin/sh
# DISCLAIMER:
#
# brew update now has a --rebase switch, thus this script is certainly obsolet.
#
# USAGE: brew-rebase [--verbose|-v] [remote] [branch]
#
# Fetches upstream and rebases HOMEBREW_REPOSITORY ($_git_repo)
@lwe
lwe / brew-more.rb
Created July 14, 2010 08:53
Try to scrape formula information from @formula.homepage.
# Small utility which uses the homepage and nokogori to get a description from the formula's homepage.
#
# As written in the homebrew wiki:
# > Homebrew doesn’t have a description field because the homepage is always up to date,
# > and Homebrew is not. Thus it’s less maintenance for us. To satisfy the description
# > we’re going to invent a new packaging microformat and persuade everyone to publish
# > it on their homepage.
#
# Too bad no packaging microformat has yet been invented, but brew-more just first looks for a
# `<meta name="description">` tag, then for an `a#project_summary_link` tag (which is used in
@lwe
lwe / Gemfile
Last active December 14, 2015 05:59
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.beta1'
gem 'sqlite3'
# THIS BREAKS IT, though when it's at the end of the file it works...
gem 'haml', '~> 3.1'
@lwe
lwe / vector.js
Created December 2, 2010 15:59
Winkel zwischen zwei Geraden (AB und CD)
// A(x1|y1) und B(x2|y2) = Touch start
// C(x3|y3) und D(x4|y3) = Current touch point
// Vektor AB
var AB_x = x2 - x1;
var AB_y = y2 - y1;
// Vektor CD
var CD_x = x4 - x3;
var CD_y = y4 - y3;