Skip to content

Instantly share code, notes, and snippets.

View noniq's full-sized avatar

Stefan Daschek noniq

View GitHub Profile
@noniq
noniq / logical.pl
Last active October 22, 2016 21:29
% Lösung des aktuellen (04/2010) P.M.-LogikRätsels
% ================================================
%
% http://www.pm-magazin.de/de/onlinetraining/logik_trainer/logikraetsel.asp
%
% Der Brite Samuel Farwell gehört zu jenen Pionieren des modernen Segelsports,
% die heute kaum noch jemand kennt. Mehrfach versuchte er zu Beginn des
% 20. Jahrhunderts alleine in seinem Boot die Welt zu umsegeln – ohne jemals
% dieses hoch gesteckte Ziel zu erreichen.
%
@noniq
noniq / changes.diff
Created March 25, 2011 14:52
We use subversion's commit-email.pl script to send info about our commits to flowdock. We customized the script so that the subject contains the first line of the log message, and the from field contains the name of the author.
Index: D:/lib/scripts/commit-email.pl
===================================================================
--- D:/lib/scripts/commit-email.pl (revision 13)
+++ D:/lib/scripts/commit-email.pl (revision 294)
@@ -39,6 +39,7 @@
use strict;
use Carp;
use POSIX qw(strftime);
+use MIME::Base64;
my ($sendmail, $smtp_server);
@noniq
noniq / gist:1044475
Created June 24, 2011 09:15
Patch trying to make akephalos kill its remote process correctly on windows
diff --git a/akephalos.gemspec b/akephalos.gemspec
index 1eee36a..ffbc980 100644
--- a/akephalos.gemspec
+++ b/akephalos.gemspec
@@ -22,6 +22,9 @@ Gem::Specification.new do |s|
if RUBY_PLATFORM != "java" && ENV["PLATFORM"] != "java"
s.add_runtime_dependency "jruby-jars"
end
+ if RUBY_PLATFORM =~ /mingw32/
+ s.add_runtime_dependency "win32-process"
@noniq
noniq / gist:1506136
Created December 21, 2011 13:54
Droplet for converting Word documents to PDF and adding a background.
property homeDir : POSIX path of (path to home folder)
on changeFileNameExtension(fileName, newExtension)
tell application "Finder" to set oldExtension to "." & name extension of alias fileName
set baseName to characters 1 thru ((offset of oldExtension in fileName) - 1) of fileName
return (baseName as string) & newExtension
end changeFileNameExtension
on convertWordFileToPdf(wordFile)
tell application "Finder" to set fileName to wordFile as string
@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)
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 / 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>.
@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: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: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),