Skip to content

Instantly share code, notes, and snippets.

View noniq's full-sized avatar

Stefan Daschek noniq

View GitHub Profile
module FlowdockNotification
class SubmissionCompleted < Base
def submission
data[:submission]
end
def api_token
"foobarbaz"
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>changed</key>
<dict>
<key>inputFormat</key>
<string>text</string>
<key>outputCaret</key>
<string>afterOutput</string>
@noniq
noniq / convert.rb
Created February 24, 2013 15:01
Convert print dumpfile from VICE C64 emulator to a real image.
#!/usr/bin/env ruby
require "logger"
require "rmagick"
class Input
attr_reader :filename
def initialize(filename)
@filename = filename
% Das Codewort besteht aus 5 Buchstaben.
% (swi-prolog)
letter(a). letter(b). letter(c). letter(d). letter(e). letter(f).
letter(g). letter(h). letter(i). letter(j). letter(k). letter(l).
letter(m). letter(n). letter(o). letter(p). letter(q). letter(r).
letter(s). letter(t). letter(u). letter(v). letter(w). letter(x).
letter(y). letter(z).
code(Xs) :-
@noniq
noniq / gist:4439645
Created January 3, 2013 00:20
Nachtbeschäftigung: Logicals in Prolog modellieren/lösen.
% Wer (Vorname) hasst am Inselleben was besonders, und was vermisst er am meisten?
%
% Vornamen: Bernd, Dirk, Jens, Hubert, Sascha, Thomas
% Gehasst werden: Früchte, Rauschen des Meeres, Sand, Schlangen, Skorpione, Wetter
% Vermisst werden: Auto, Bier, Ehefrau, Fernsehen, Kinder, Kumpels.
loesung(Vornamen, Hasst, Vermisst) :-
% 1. Der Mann auf Position 5 vermisst seine Kinder.
nth(5, Vermisst, kinder),
@noniq
noniq / gist:4147547
Created November 26, 2012 10:25
Prolog nonogram solver
% Succeeds if `Lines` represents the nonogram specified by `ColumnSpecs` and
% `LineSpecs`. For example:
%nonogram
% 1
% 2 1 2
% +------
% 1 | . # . ColumnSpecs = [[2], [1,1], [2]]
% 1 1 | # . # LineSpecs = [[1], [1,1], [3]]
% 3 | # # # Lines = [[0,1,0], [1,0,1], [1,1,1]]
nonogram(ColumnSpecs, LineSpecs, Lines) :-
@noniq
noniq / gist:3865897
Created October 10, 2012 14:15
Rails validator for counting newlines as one character
# Browsers send newlines from textareas as "\r\n", thus each newline is counted
# as two chars when using Rails’ default LengthValidator.
#
# Of course it would also be possible to convert "\r\n" to "\n" in the controller
# or model, but in my app it’s simpler do use a custom validator.
class LengthCountingNewlinesAsOneValidator < ActiveModel::Validations::LengthValidator
def validate_each(record, attribute, value)
value = value.gsub("\r\n", "\n")
super
end
@noniq
noniq / gist:2318406
Created April 6, 2012 09:15
Test failures in delocalize/spike (Ruby 1.9.3, Rails 3.2.3)
1) Failure:
test_delocalizes_localized_date_without_year(DelocalizeActiveRecordTest) [delocalize/test/delocalize_test.rb:53]:
<Mon, 19 Oct 2009> expected but was
<Fri, 19 Oct 2012>.
2) Failure:
test_delocalizes_localized_time_(DST)(DelocalizeActiveRecordTest) [delocalize/test/delocalize_test.rb:79]:
<Sun, 01 Mar 2009 09:00:00 CET +01:00> expected but was
<Fri, 06 Apr 2012 09:00:00 CEST +02:00>.
def validate_inputs
self.form.descendants.any_in(:html_tag => ["input", "select", "textarea"]).excludes("html_attributes.type" => "submit").each do |element|
attr = "input_" + element.html_attributes["name"]
element.errors.add(:attr, " muss ausgefüllt werden") if element[attr].blank? && element["required"]
...
end
end
@noniq
noniq / concat.rb
Created February 5, 2012 17:32
Script for building a single giant compass-all.scss file.
# Usage:
# ruby concat.rb /path-to-compass-gem/frameworks/compass/stylesheets/_compass.scss > compass-all.scss
@seen = []
def concat(file)
File.foreach(file) do |line|
if line =~ /^\s?@import "(.+?)";/
import = $1
unless @seen.include?(import)