Skip to content

Instantly share code, notes, and snippets.

View Papierkorb's full-sized avatar

Stefan Merettig Papierkorb

View GitHub Profile
@Papierkorb
Papierkorb / ssl_hack.rb
Created June 10, 2015 16:46
SSL with Capybara and Selenium
# Hack for Capybara to use SSL connections using selenium.
#
### Usage:
# Require this from rails_helper.rb
#
### Steps to generate a SSL certificate on a Linux box:
# 0. Starting from 'Rails.root'
# 1. Generate private key. Type in some password.
# $ openssl genrsa -des3 -out private.key 4096
# 2. Generate certificate sign request
@Papierkorb
Papierkorb / concern_helper.rb
Created September 20, 2015 16:15
Rails migration helper code for updating model concern-specific columns
# Helper methods for writing migrations for concern specific things.
module ConcernHelper
# Returns an array of symbols containing the table names of all models
# including 'concern'. If a block is given, it's called for each table name.
#
# Example usage:
# class AddSomethingToAllFooables
# include ConcernHelper
#
$ ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby benchmark.rb
user system total real
RedCarpet 0.220000 0.000000 0.220000 ( 0.227063)
kramdown 52.250000 0.000000 52.250000 ( 52.328927)
marked.js 3.660000 0.020000 3.680000 ( 3.632203)
# Machine:
# File.read is inherited from IO.read, which in turn allows the user to call out
# to the shell and thus might turn any call to {File.read} into a Remote Code
# Execution vulnerability.
#
# This is insane. So get rid of it.
class File
def self.read(path, *opt)
raise Errno::ENOENT, "Shell methods not allowed" if path.start_with? '|'
super
end
#!/usr/bin/env ruby
# Ejabberd authentication back-end script in Ruby.
# Works with Ruby 2.2.
# Dependency: RestClient gem
root = File.realpath("#{File.dirname __FILE__}/..")
URL = 'http://URL_TO_YOUR/service'
LOG_FILE = "#{root}/log/ejabberd_auth_tool.log"
@Papierkorb
Papierkorb / method_shorthand.diff
Created February 28, 2016 20:42
WIP foo.method(:bar) == foo->bar shorthand
diff --git a/defs/id.def b/defs/id.def
index e186725..b603fe6 100644
--- a/defs/id.def
+++ b/defs/id.def
@@ -39,6 +39,7 @@ firstline, predefined = __LINE__+1, %[\
bt
bt_locations
call
+ method
mesg

What's the problem?

  1. Describe what you're trying to do (Not how you're doing it)
  2. Describe what you expected to see
  3. Describe what you're getting instead
@Papierkorb
Papierkorb / 000.md
Last active September 13, 2019 13:44
Memory Management code taken from my Crystal OS project (AMD64!).

Hello there

This code comes from my operating system project, written in Crystal. The target platform was AMD64, so that's why it uses 64-Bit integers all over the place. The whole thing isn't open (yet?), but I stopped working on it so..

Take what you want from it, however a short source description, e.g. using a in-source comment, to this gist or to me would be really neat :)

@Papierkorb
Papierkorb / 00_LICENSE.md
Last active April 25, 2017 19:41
Struct-by-reference helper class

Copyright (c) 2017 Stefan Merettig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

@Papierkorb
Papierkorb / set-file-association.rb
Created January 14, 2017 00:04
Set KDE/XDG file associations in bulk
#!/usr/bin/env ruby
# A script to bulk change file associations. Intended for KDE, but might work
# with other XDG conforming software. Run it without arguments to see how to
# use it. Created by me out of frustration, so the code just works ;)
require "inifile" # gem install inifile
ASSOC_FILE = "#{ENV['HOME']}/.config/mimeapps.list"
ASSOC_FILE_BAK = "#{ASSOC_FILE}.bak"