Skip to content

Instantly share code, notes, and snippets.

Sven Pachnit 2called-chaos

Block or report user

Report or block 2called-chaos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@2called-chaos
2called-chaos / kernel.rb
Created Mar 10, 2014
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.
View kernel.rb
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 Aug 29, 2015
nginx htpasswd add user (perl script)
View nginx_htpasswd
#!/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 Jul 3, 2014
Punch in the face list
View punch_list.pain
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 Aug 29, 2015
Expand range like strings into lists/arrays with ruby, example at the bottom
View string_expand_ranges.rb
#---
# 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 Aug 29, 2015
Essential IRC rules (to be continued)
View irc.md

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 Oct 4, 2014
Bash function if you trust your skills
View faith.sh
function with_faith { $@ &> /dev/null; }
View gist:50f488044bba19c32903
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 Oct 13, 2014
Automatic Server Restart (MCL handler)
View automatic_server_restart.rb
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 Oct 14, 2014
Simple class to find memory eaters in Ruby / Rails applications
View memprof.rb
# 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 Aug 29, 2015
Piwik in Ruby on Rails with Turbolinks (and proxy)
View piwik_analytics.coffee
# 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: ->
You can’t perform that action at this time.