Skip to content

Instantly share code, notes, and snippets.

use_module(library(date)).
event(asleep).
event(wokeup).
eventdb(Ts,X,I) :- event(X), call(X,Y), parse_time(Y,Ts), aggregate(min(IArg), eventdb(_,_,IArg), IMin), I=IMin+1.
asleep('2015-03-28 23:00').
asleep('2015-03-28 22:00').
wokeup('2015-03-28 02:00').
birthday(5,15). birthday(5,16). birthday(5,19).
birthday(6,17). birthday(6,18).
birthday(7,14). birthday(7,16).
birthday(8,14). birthday(8,15). birthday(8,17).
countd(D,C) :- #count{X: birthday(X,D) } = C, birthday(_,D).
countm(M,C) :- #count{X: birthday(M,X) } = C, birthday(M,_).
% Satz 1
result(M,D) :- birthday(M,D), countm(M,C1), countd(D,C2), C1 > 1, C2 > 1.
@esad
esad / rgp.rb
Created February 13, 2009 19:47
#!/usr/bin/ruby
#
# Recursive git pull - will go into first-level subdirectories that are git repos and execute "git pull", stopping on first unsuccessful pull
# @Copyleft 2009 Esad Hajdarevic <esad@esse.at> http://dev.soup.io/
repos = Dir["*/.git"].map {|path| path.chomp!("/.git") }
if repos.empty?
puts "No git repositories found"
else
@esad
esad / pong.rb
Created May 23, 2009 01:35
Sketch for a game of pong in kyoto
require 'kyoto'
use 'actors/velocity'
use 'actors/bound_to_world'
use 'game/pausable'
use 'game/score'
use 'color'
use 'collision_detection'
class Paddle < Actor
int d = [[n toStringWithDecimalPlaces:0] length];
if (d > decimals) decimals = d;
require File.join(File.dirname(__FILE__),'spec_helper')
def parse(str)
Timespan.parse(str).map {|span| [span.day_of_week,span.from_h,span.from_m,span.to_h,span.to_m] }
end
mon,tue,wed,thu,fri,sat,sun = 1,2,3,4,5,6,7
describe Timespan do
it 'parses single day/single hourspan' do
esad@gagarin:~/Projects/appscape/vapor(master)$ irb
irb(main):001:0> gem 'actionpack', '3.0.0'
=> true
irb(main):002:0> require 'action_view/helpers/date_helper'
NameError: uninitialized constant ActionView::Helpers::TagHelper::ERB
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/helpers/tag_helper.rb:10
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:in `require'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/helpers/date_helper.rb:2
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:in `gem_original_require'
var Store = Brick.Model("Store");
var Chain = Brick.Model("Chain").hasMany(Store,{url:"/chains/<%= id %>/stores.json"});
var Country = Brick.Model("Country").hasMany(Chain);
@esad
esad / gist:1015087
Created June 8, 2011 18:59
Prefix routes in sinatra
# Prefix routes with /api/v1
%w(get post head options put).each do |method|
eval <<-RUBY
def self.#{method}(path, opts={}, &bk)
super("/api/v1"+path,opts,&bk)
end
RUBY
end
@esad
esad / gist:1311719
Created October 25, 2011 07:33
Esad's whole foods diet
Eat as much as you want.
Whole foods.
Protein rich, low fat.
No preservatives except salt.
No spices.
No industrially processed food, except for packaging (i.e. canned tuna).
Low intake of dairy products.
Eggs without yolk.
Only non-carbonated water and juice made directly from fruit in front of your eyes.
Only pure, freshly grind espresso. Two cups/day max.