Skip to content

Instantly share code, notes, and snippets.

View dmke's full-sized avatar

Dominik Menke dmke

View GitHub Profile
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
$ ruby re_bench.rb
Rehearsal --------------------------------------------------------
(?-mix:^[a-zA-Z]$) 0.780000 0.000000 0.780000 ( 0.783924)
(?i-mx:^[a-z]$) 0.790000 0.000000 0.790000 ( 0.789410)
(?-mix:\A[a-zA-Z]\z) 0.370000 0.000000 0.370000 ( 0.373894)
(?i-mx:\A[a-z]\z) 0.370000 0.000000 0.370000 ( 0.373349)
----------------------------------------------- total: 2.310000sec
@dmke
dmke / edit.html.haml
Created March 31, 2014 15:23
Devise registration form, prepared for Bootstrap 3 (w/o Simple Form)
-# app/views/devise/registrations/edit.html.haml
%h1.page-header
Edit
= resource_name.to_s.humanize
= form_for resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'form-horizontal' } do |f|
= devise_error_messages!
.form-group
@dmke
dmke / example.rb
Last active August 29, 2015 14:15
Hexdump in Ruby
random_twitter_message = (1..140).map{ rand 0xFF }.pack("C*")
hexdump random_twitter_message
# 0000: af 98 02 2b 25 13 01 42 b8 cd 3a a5 23 07 c2 43 |...+%..B ..:.#..C|
# 0010: c0 af bd 65 3e a7 c0 4c 26 b9 1e 54 cc c3 5b 3f |...e>..L &..T..[?|
# 0020: db d6 86 76 22 d4 31 ab 32 fe b6 32 f4 d4 1c 01 |...v".1. 2..2....|
# 0030: f6 5d 25 8c 64 9b 18 3a 9d 50 14 a2 86 79 a6 f2 |.]%.d..: .P...y..|
# 0040: da 50 f3 70 b6 bc e4 76 15 db 2f b7 f6 9c 88 d0 |.P.p...v ../.....|
# 0050: 63 95 23 66 b3 20 f6 ab 62 a6 28 92 c7 6d a9 e0 |c.#f. .. b.(..m..|
# 0060: 1c 2d fe 12 3e fd 8b 95 47 4d b2 14 07 e8 6b 6c |.-..>... GM....kl|
@dmke
dmke / README.md
Last active August 29, 2015 14:22
Ruby Symbol GC

Just a small benchmark to clear up the myth, Ruby wouldn'd garbage collect any Symbols. In fact, MRI 2.2.0 introduced Symbol GC in December 2014 (see notable changes in the release announcement).

The benchmark is quite simple: It basically cretes a bunch of Symbols via String#to_sym and counts Symbol::all_symbols afterwards.

I've used rbenv to test the Symbol GC (or the lack thereof) of these interpreter implementations:

  • 1.9.3-p551
  • 2.0.0-p645
  • 2.1.6
  • 2.2.2
@dmke
dmke / test-results-0.10.log
Created April 28, 2016 19:42
influxdb-ruby GH-141
influxdb-ruby: 0.3.0
influx server: 0.10.2
purging existing data...
generating data:
UNIT_000 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_001 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_002 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_003 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_004 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
@dmke
dmke / convert.sh
Created September 26, 2016 13:30
Convert unifi_sysvinit_all.deb to DIY.tar.gz
#!/bin/bash -e
self=$(readlink -f "$0")
root=$(dirname "$self")
version="$1"
checksum="$2"
if [ -z "$version" ]; then
echo >&2 "Missing version specifier."
@dmke
dmke / ac1200.dts
Created November 14, 2016 14:44
device tree sources (shortened)
#include zbt.dsti
&spi0 {
m25p80@0 {
partition@50000 {
reg = <0x50000 0x1fb0000>
};
};
};
@dmke
dmke / README.md
Created November 17, 2016 14:58
mt7261 32M reset patch

"Frozen soft reset" on MT7261 SoCs with 32M flash

This hack is derived from [this mail][] by Paul Fertser on openwrt-devel.

  • When using 32M flash, the SPI bus needs to be reconfigured to use 4-byte addressing mode, instead of the usual (?) 3-byte mode.
  • Issueing a soft reset without this patch leaves the bus in 4-byte mode, which then crashes the system because the SoC tries (and fails) to communicate in 3-byte addressing mode.
  • Writing the opcodes brings the SPI back into 3-byte addressing mode,
@dmke
dmke / funky.go
Last active May 22, 2017 16:58
vscode-go #936
package main
var n = func() int { return 42 }()
var (
m = func() int { return 23 }()
o = getTruth()
)
func main() {

Performing UDP tunneling through an SSH connection

Intro

The Swiss ISP [Bluewin][] sucks. Their DNS are often down. A friend even received advice from Bluewin technicians to not use their own DNS!... But then, it is quite hard to gain access to another DNS for free, if you don't have access to a co hosted machine.

In this document, we'll access another machine's network internal DNS services (UDP