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.
View GitHub Profile
@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;
@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>
HANDLE hClient = NULL;
PWLAN_INTERFACE_INFO_LIST pIntfList = NULL;
DWORD negotiatedVersion = 0;
DWORD res = 0;
int i = 0;
// get handle
res = WlanOpenHandle(WLAN_API_VERSION, NULL, &negotiatedVersion, &hClient);
if (res != ERROR_SUCCESS) {
if (hClient != NULL) WlanCloseHandle(hClient, NULL);
LINK_ONLY = {
:elements => %w{a},
:attributes => {
'a' => %w{href}
},
:add_attributes => {
'a' => { 'rel' => 'external nofollow' }
},
module TelHelper
# Erstellt einen <a href="tel:..."> link.
def tel_to(telephone_number, name = nil, html_options = {})
href = html_escape telephone_number.to_s.strip.sub(/\A\+/, '00').gsub(/(\(.+\))/, '').gsub(/[^\d]/, '')
content_tag "a", name || telephone_number, html_options.stringify_keys.merge("href" => "tel:#{href}".html_safe)
end
end
@lwe
lwe / serveme
Created August 18, 2011 14:32
Start a simple HTTP server to serve current directory.
#!/usr/bin/ruby -w
require 'rubygems'
require 'optparse'
require 'rack'
# setup options
options = { :Port => 4000, :Host => "0.0.0.0" }
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: serveme [-p PORT] [-h HOST] [-s thin|webrick|...]"
@lwe
lwe / fail.rb
Created December 20, 2011 13:50
require 'rubygems'
require 'nokogiri'
puts "Platform: #{RUBY_PLATFORM}"
puts "Nokogiri: #{Nokogiri::VERSION}"
xml = <<XML
<foo:bar>
<some>value</some>
<other>1234</other>
{
"took" : 45,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 4,
@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 / _rbfu.zsh
Created July 3, 2012 18:00
rbfu autocompletion for zsh
#compdef rbfu
local curcontext="$curcontext" state line _rubies _rubies_dir ret=1
_arguments -w -S \
'(-)--help[show usage and exit]: :->noargs' \
'1: :->versions' \
'*::: :->args' && ret=0
case $state in