Skip to content

Instantly share code, notes, and snippets.

View kakra's full-sized avatar
🏠
Let's inject fun into Linux Gaming

Kai Krakow kakra

🏠
Let's inject fun into Linux Gaming
View GitHub Profile
@kakra
kakra / defrag-preloaded.rb
Last active December 17, 2015 00:19
A very basic ruby script for defragmenting files on btrfs loaded by preload daemon
#!/bin/env ruby
#
# basic concept script for defragmenting files on btrfs loaded by preload daemon
#
# Actually, this idea is working in the spirit of systemd's readahead function which
# can defrag (and relocate?) files on btrfs during boot. Preload takes on where
# readahead stops working, so it should be a great place to continue integrating that
# idea there. This script is actually here, to test the impact of such an idea and
# find first caveats and show-stoppers.
#
@kakra
kakra / php-server.sh
Created August 15, 2011 09:07 — forked from kakra/gist:1085054
PHP Stand-Alone Server based on LigHTTPd
#!/bin/bash
TMPNAME=$(mktemp /tmp/lighttpd-cgi-php-XXXXXX)
if [ -d "www" ]; then
DOCROOT=$(pwd)/www
else
DOCROOT=$(pwd)
fi
@kakra
kakra / gist:1085054
Created July 15, 2011 16:49
PHP Stand-Alone Server based on LigHTTPd
#!/bin/bash
TMPNAME=$(mktemp /tmp/lighttpd-fastcgi-php-XXXXXX)
cat >$TMPNAME.conf <<-EOF
server.bind = "localhost"
server.port = "3000"
server.document-root = "$(pwd)"
server.indexfiles = ("index.php", "index.html", "index.htm", "default.htm")
server.modules += ("mod_cgi", "mod_accesslog")
@kakra
kakra / associate_by.rb
Created October 15, 2010 17:29
Associates models to a parent by other methods, similar to delegates
# AssociateBy
#
# Associates models to a parent by other methods, similar to delegates but
# changing the association itself instead of the associated object when
# writing to the delegated attribute.
#
# Usage:
# ActiveRecord::Base.class_eval { include AssociateBy }
#
# Example:
@kakra
kakra / filter_payment_methods.rb
Created October 14, 2010 22:10
Filter payment methods in Spree depending on the shipping name
# Filter payment methods in Spree depending on the shipping name,
# use the following snippet within your activation method to
# make it work:
#
# CheckoutsController.class_eval { include FilterPaymentMethods }
#
# The magic happens within the InstanceMethods module, change the
# regexp to fit your needs.
#
# Kai Krakow, http://github.com/kakra
@kakra
kakra / hardlink-deduplication.rb
Created May 23, 2010 12:44
Simple proof-of-concept of file deduplication through hardlinks: Generates a script of ln command lines to run in bash
@kakra
kakra / tableless.rb
Created November 29, 2009 22:23
tableless ActiveRecord models
# Tableless ActiveRecord models
# http://stackoverflow.com/questions/315850/rails-model-without-database/318919#318919
class Tableless < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
#slide-images {
position: relative;
display: block;
margin: 0px;
padding: 0px;
width: 738px;
height: 234px
overflow: hidden;
}
@kakra
kakra / patch_delayed_job.rb
Created November 13, 2009 15:43
patch DelayedJob in the case no default_timezone is defined
module Delayed
class Job < ActiveRecord::Base
def self.db_time_now
(ActiveRecord::Base.default_timezone == :utc) ? Time.now.utc : Time.zone.now
rescue NoMethodError
Time.now
end
end
@kakra
kakra / application_helper.rb
Created August 12, 2009 11:06
Auto-labelling formbuilder, use with :builder => LabellingFormBuilder
module ApplicationHelper
def labelled_form_for(name, object, options, &proc)
form_for(name, object, options.merge(:builder => LabellingFormBuilder), &proc)
end
def multipart_form_for(name, object, options, &proc)
html_options = options.delete(:html) || {}
html_options.merge!(:multipart => true)
form_for(name, object, options.merge(:html => html_options), &proc)