This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Operating with plain arrays: | |
class Array | |
def scanl(init, &f) | |
return [init] if empty? | |
reduce([init]){ |xs, x| xs << f.(xs.last, x) } | |
end | |
def scanl1(&f) | |
return if empty? # might consider returning [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# encoding: UTF-8 | |
require 'rubygems' | |
require 'fsevent' | |
require 'shellwords' | |
class Time | |
def age_in_seconds(now = Time.now) | |
now - self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ⌘⌫ Element | |
// @description ⌘⌫ deletes element under cursor, ⌘Z puts back | |
// @match *://*.* | |
// ==/UserScript== | |
let undoWindow = 3000 // can undo for this long | |
let undoCooldown = 1500 // will prevent default undo for this long after last undo | |
let scheduledDeletion = null // timeout id for deleteElements | |
let lastHide = 0 // timestamp for last element was hidden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
# encoding: UTF-8 | |
require 'yaml' | |
require "base64" | |
require 'rexml/document' | |
class PList < BasicObject | |
ELEMENT_PROCESSORS = {} | |
def self.process_element_named(name, &block); ELEMENT_PROCESSORS[name.to_s] = block; end | |
def self.process_element(elt) ; ELEMENT_PROCESSORS[elt.name][elt]; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Youtube ensure HD | |
// @description Sets youtube player to highest resolution if drops from an HD res | |
// @match *://www.youtube.com/watch* | |
// @match *://youtu.be/watch* | |
// ==/UserScript== | |
let intervalID = setInterval(()=> { | |
let qs = (q) => document.querySelector(q) | |
let qsa = (q) => [...document.querySelectorAll(q)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby1.9 | |
# encoding: UTF-8 | |
require 'appscript' | |
include Appscript | |
itunes = app("iTunes") | |
pos = itunes.player_position.get | |
pos = pos > 30 ? pos - 30 : pos / 2 | |
itunes.player_position.set pos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Previous versions of this gist brought to you by major OCD. | |
# I now leave you with my pick. | |
git branch | ack -o '(?<=^\* ).*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'yaml' | |
require 'rexml/document' | |
class PlistWriter | |
PLIST_STUB_DOC = %q[ | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"></plist>] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator « { precedence 131 associativity left } | |
func «<A,B,C>(a:A, f:(A,B) -> C) -> B -> C { return { f(a,$0) } } | |
infix operator » { precedence 131 associativity left } | |
func »<B,C>(f:(B) -> C, b:B) -> C { return f(b) } | |
infix operator < { precedence 131 associativity left } | |
func <<A,B,C>(a:A, f:(A,B) -> C) -> B -> C { return { f(a,$0) } } | |
infix operator > { precedence 131 associativity left } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
s = ARGF.read =~ /Freitag, 13. Mai 2016.*?(?=\n\n)/m && $& | |
s.gsub! /^(\d\d)\.(\d\d)\u00A0Uhr\n/, "\\1:\\2h -- " | |
days = [] | |
s.lines.each do |l| | |
case l | |
when /^\d\d:\d\dh -- Einlaß/ then :pass | |
when /Mai 2016$/ then days << [l, []] | |
when /^\d\d:\d\dh -- / then days.last[1] << l.sub(/\Z/, " -- @ #{$x}") |
NewerOlder