Skip to content

Instantly share code, notes, and snippets.

View niklas's full-sized avatar

Niklas H niklas

View GitHub Profile
@niklas
niklas / compass-css-sprites-alternatives.txt
Last active August 29, 2015 13:56
compass CSS-Sprites alternatives
CSS-Sprites alternatives
https://github.com/flyerhzm/css_sprite
* minimagick!
* dirty code
* hard to customize until refactored
https://github.com/railsjedi/sprite
@niklas
niklas / Backup.rb
Created May 19, 2014 15:14
Backup script using git
#!/usr/bin/env ruby
medium = ARGV.shift || 'Spinn'
user = ENV['USER']
hostname = `hostname`.chomp
path = "/media/#{user}/#{medium}"
rc = "#{ENV['HOME']}/.bashrc-backup"
unless File.directory?(path)
@niklas
niklas / puppet.conf
Last active August 29, 2015 14:01
maybe broken puppet.conf
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter:/home/guy/puppet/modules/rvm/lib/facter
prerun_command=/etc/puppet/etckeeper-commit-pre
postrun_command=/etc/puppet/etckeeper-commit-post
pluginsync=true
server=hurlg.lanpartei.de
@niklas
niklas / autotop.rb
Created July 14, 2014 18:16
Setup correct resolutions based on connected displays
#!/usr/bin/ruby
def dpi
147
end
def desktop
system "xrandr --output VGA1 --auto --left-of LVDS1 --output LVDS1 --auto --primary --dpi #{dpi}"
system "xset dpms force on" # wake up monitor from power saving mode
system "marble-mouse left"
# works with textnodes, too
Nokogiri::XML::Node.class_eval do
def to_hash
unless children.empty?
h = children.to_hash
if h.length == 1 && h.has_key?(:onlytext)
{ name => h[:onlytext] }
else
{ name => children.to_hash }
@niklas
niklas / views_for_every_user.rb
Last active September 9, 2015 11:08
A View for every User
class CompleteCapture < ActiveRecord::Base
TablesName = /\Acomplete_capture(\d+)s\z/
SubClassName = /\ACompleteCapture(\d+)\z/
self.abstract_class = true
cattr_accessor :company
include CapturedAt
class << self
@niklas
niklas / sizeof64.c
Created January 3, 2011 22:50
trying to find out if ruby 1.9.2 does not implement syscall() on amd64 because of the different sizes if int and long
/*
please do me a favour: do the following on a amd64 ubuntu
$ gcc -o sizeof64 sizeof64.c
$ ./sizeof64
are they different? would this be OK? If not, what could cause this?
If it is OK, why is ruby 1.9 not able to implement syscall()
https://github.com/ruby/ruby/blob/ruby_1_9_2/io.c#L7529
@niklas
niklas / ruby_rvm_system_invocation.rb
Created April 8, 2011 12:31
How to run a system command from ruby within a clean bash that has never sourced rvm using a custom ruby version
#!/usr/bin/env ruby
# How to run a system command from ruby within a clean bash that has never sourced rvm using a custom ruby version
# 1) install rvm as the correct user
# 2) do NOT follow the instructions about sourcing and adding this to your .bashrc
# 3) run the following (change the versions accordingly)
ruby_versions = %w(ruby-1.8.7-p330 rbx-head)
@niklas
niklas / simple_form_form_builder.rb
Created April 20, 2011 14:42
get real buttons in forms that is stylable
# now you can use
# form.button :submit
# to get a real button that is stylable
class SimpleForm::FormBuilder
def submit_button(title=nil, options={}, &block)
title, options = nil, title if title.is_a?(Hash)
title ||= submit_default_value
options[:type] = 'submit'
template.add_class_to_html_options(options, 'submit')
@niklas
niklas / lxc.rb
Created April 24, 2011 16:44
Setup an lxc-container (chef recipe)
package 'debootstrap'
package 'apt-cacher-ng'
package 'inotify-tools'
include_recipe 'lxc::manage'
include_recipe 'lxc::network_bridge'
include_recipe 'lxc::dns'
host = node[:container]