Skip to content

Instantly share code, notes, and snippets.

View sebastiangeiger's full-sized avatar
🐕

Sebastian Geiger sebastiangeiger

🐕
View GitHub Profile
@sebastiangeiger
sebastiangeiger / find_bad_migration.sh
Created July 25, 2013 19:31
Toy script that runs each rails migration individually to determine which one fails. COLORS, YAY!
#!/bin/bash
reset='\e[0m';
green='\e[1;32m';
red='\e[1;31m';
rake db:drop db:create
ls -1 db/migrate | sort | cut -f 1 -d '_' | while read version; do
printf "${version}"
ERROR=$(((rake db:migrate:up VERSION=${version}; ) 1>/dev/null) 2>&1)
if [ $? -eq 0 ]; then
printf "\r${green}${version}${reset}\n"
remove_file "README.rdoc"
create_file "README.md", "TODO"
gem 'mysql2'
gem 'devise'
gem 'cancan'
gem "slim-rails"
remove_file "README.rdoc"
create_file "README.md", "TODO"
gem 'devise'
gem 'cancan'
gem "slim-rails"
gem_group :assets do
gem 'anjlab-bootstrap-rails', '>= 2.3', :require => 'bootstrap-rails'
@sebastiangeiger
sebastiangeiger / simulation.rb
Created May 16, 2013 19:04
Simulating different responsive strategies
simulated_widths = (100 ... 1024).to_a.reverse
puts "Maximizing the width"
simulated_widths.each do |width|
number_of_elements_per_row = (width/200.0).ceil
element_width = (width/number_of_elements_per_row).floor #floor to get even pixel values
puts " #{width}px: #{number_of_elements_per_row} elements with #{element_width}px"
end
puts "Minimizing the width"
@sebastiangeiger
sebastiangeiger / check_verified_strategy.rb
Created April 15, 2013 15:50
Devise strategy used when an admin has to verify users before they are granted access to a site.
# encoding: UTF-8
class CheckVerifiedStrategy < ::Devise::Strategies::Base
def valid?
params[:user] and params[:user][:email]
end
def authenticate!
user = User.where(email: params[:user][:email]).first
if user and not user.verified?
fail!(I18n.t('profile.requested'))
else
ruby -e "require 'time';puts ((Time.parse('Jun 11 11:50') - Time.now) / 60 / 60 / 24).round.to_s + ' days left'"
@sebastiangeiger
sebastiangeiger / filereader.html
Created May 13, 2012 13:36
FileReader API example
<html>
<title>File API</title>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log("loaded");
var holder = document.getElementById('holder'),
state = document.getElementById('status');
Gem::Specification.new do |s|
s.name = 'genetic_algorithm'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.author = 'Sebastian Geiger'
s.email = 'sebastian.geiger@gmail.com'
s.summary = 'A primitive and unfinished genetic algorithm'
s.description = 'This algorithm will take a vector of a fixed length togther with a sum constraint and an executable. The executable must return the performance indicator, the vector should be consumed by the block in order to configure its operation. The performance measure is used to optimize the vector. This is work in progress!'
s.files = ['genetic_algorithm.rb']
@sebastiangeiger
sebastiangeiger / ambiguities.py
Created December 22, 2011 15:23
NLTK homework
import locale
import nltk
from nltk.corpus import wordnet as wn
from nltk.tag.simplify import simplify_wsj_tag
def main():
string = "I saw a man who is 98 years old and can still walk and tell jokes."
tokens = nltk.word_tokenize(string)
print nice_formatting(combinations_without_wordtype(tokens)) + " possible combinations when not taking wordtype into account"
print nice_formatting(combinations_with_wordtype(tokens)) + " possible combinations when taking wordtype into account"
@sebastiangeiger
sebastiangeiger / PolymorphismTest.cpp
Created October 26, 2011 11:14
Polymorphism in C++
#include <iostream>
#include <string.h>
#include <boost/tr1/memory.hpp>
class Image {
public:
Image(std::string className = "Image")
: className_(className)
{}