Skip to content

Instantly share code, notes, and snippets.

View 2called-chaos's full-sized avatar
😐
perpetually bored

Sven Pachnit 2called-chaos

😐
perpetually bored
View GitHub Profile
@2called-chaos
2called-chaos / kernel.rb
Created March 10, 2014 14:58
Call ruby method or lambda like a proc. Calls a method with the maximum possible amount of arguments. Ruby's arity telling is too inaccurate so we just try to call the method with everything we have and if this raises an ArgumentError we examine the maximum allowed amount of arguments and pass those.
module Banana
# Provides low level support functionalities.
module Kernel
# Calls a method with the maximum possible amount of arguments.
#
# Ruby's arity telling is too inaccurate so we just try to call the method
# with everything we have and if this raises an ArgumentError we examine the
# maximum allowed amount of arguments and pass those.
#
# Dont believe me?
@2called-chaos
2called-chaos / nginx_htpasswd
Last active August 29, 2015 14:01
nginx htpasswd add user (perl script)
#!/usr/bin/perl
# Script origin: http://wiki.nginx.org/Faq#How_do_I_generate_an_.htpasswd_file_without_having_Apache_tools_installed.3F
# Install:
# aptitude install -y curl \
# && curl -o /usr/local/bin/nginx_htpasswd \
# https://gist.githubusercontent.com/2called-chaos/286965e2a4b5c1aaf056/raw/nginx_htpasswd \
# && chmod +x /usr/local/bin/nginx_htpasswd
use strict;
chomp(my $filename=$ARGV[0]);
@2called-chaos
2called-chaos / punch_list.pain
Created July 3, 2014 09:29
Punch in the face list
This is a list of people (or - in most cases - companies as I don't have an individual to blame) whom I would like to make a fist gift.
###############################################################################################################
Skype - for having the shittiest chat application ever and refuse to open the chat API so that I don't have to install this shit (I don't want to use it but a lot of people use Skype exclusively for whatever reason)
Apple - for having the shittiest app store I can imagine (it was okay for iOS but the OS X implementation is just a piece of crap). It's not that you can break it really easily (so that you can't download/update anymore) but there is no archive for older versions (how often did I update to get a broken application (good to have TimeMachine) and how often did I bought an application which was broken (bad luck, an update is usually not far away but why can't I just USE THE PREVIOUS VERSION?!?!?!?!?) and how often did I pray for a download function (like
@2called-chaos
2called-chaos / string_expand_ranges.rb
Last active August 29, 2015 14:05
Expand range like strings into lists/arrays with ruby, example at the bottom
#---
# Copyright (c) 2013, Sven Pachnit
# Published under the MIT license
#
# I wrote this in 15 minutes, I have no idea about performance.
# CPAN's String::Range::Expand is the only thing I was able to
# find and Perl is not good for my Ruby eyes ;)
#---
# result of me being lazy :)
@2called-chaos
2called-chaos / irc.md
Last active August 29, 2015 14:06
Essential IRC rules (to be continued)

IRC – that's how it works!

These "rules" are especially true for big channels with dozens and hundreds of users.

1. Don't ask to ask

Most channels insist on this rule. Don't ask if someone may help or is "there". Just ask your question (a greeting isn't wrong though) and be patient.

2. Highlighting

A very important one! If you ask a question you might get responses which are prefixed with your name:

@2called-chaos
2called-chaos / faith.sh
Created October 4, 2014 23:09
Bash function if you trust your skills
function with_faith { $@ &> /dev/null; }
in your ~/.profile
alias restartmc='ssh geekyamc@hugo.breitzeit.de "cd _terra && chruby-exec 1.9 -- mcir restart"'
@2called-chaos
2called-chaos / automatic_server_restart.rb
Created October 13, 2014 15:56
Automatic Server Restart (MCL handler)
module Mcl
Mcl.reloadable(:AutomaticServerRestart)
class AutomaticServerRestart < Handler
def setup
@stop_at = 1.hour.from_now
end
def tick!
# only check every 240 MCL ticks == 60 seconds
@2called-chaos
2called-chaos / memprof.rb
Created October 14, 2014 14:30
Simple class to find memory eaters in Ruby / Rails applications
# put this in an initializer
# and use/output MemProfiler.profile all over the place (we use HTML comments).
class MemProfiler
def self.profile
Thread.main[:memprof_last_tick] ||= 0
Thread.main[:memprof_last_tick] += 1
was = Thread.main[:memprof_last_val]
now = Thread.main[:memprof_last_val] = measure
if was
@2called-chaos
2called-chaos / piwik_analytics.coffee
Last active August 29, 2015 14:08
Piwik in Ruby on Rails with Turbolinks (and proxy)
# Heavily inspired by https://gist.github.com/erpe/8586565
# Call `PiwikAnalytics.init()` once per document load, e.g.:
# unless $(document).data("piwik_loaded")
# PiwikAnalytics.init()
# $(document).data("piwik_loaded", "loaded")
class @PiwikAnalytics
@trackerUrl: -> "//analytics.example.net"
@siteId: ->