Skip to content

Instantly share code, notes, and snippets.

View jurriaan's full-sized avatar
:octocat:
What's happening?

Jurriaan Pruis jurriaan

:octocat:
What's happening?
View GitHub Profile
@jurriaan
jurriaan / reset_serial.py
Created March 17, 2024 09:35
Reset serial port of ESP32 / Arduino devices. Can be used to reset a serial port before running esptool.
import serial
import time
import sys
import serial.tools.list_ports
ports = serial.tools.list_ports.comports()
print("Current serial ports:\n")
function kns
echo $argv | read -l namespace context
if test -z "$context"
set context (kubectl config current-context)
end
if test -z "$argv"
echo "USAGE: kns NAMESPACE [context]"
else
@jurriaan
jurriaan / bootstrap.sh
Created August 22, 2016 11:41
bootstrap.sh with librdkafka 0.9.1
#!/bin/bash
#
# This script provides a quick build alternative:
# * Dependencies are downloaded and built automatically
# * kafkacat is built automatically.
# * kafkacat is linked statically to avoid runtime dependencies.
#
# While this might not be the preferred method of building kafkacat, it
# is the easiest and quickest way.
#
@jurriaan
jurriaan / cbs.rb
Last active November 1, 2015 11:32 — forked from koenbollen/cbs.go
ClipBoardServer (in Ruby, for OSX)
require 'webrick'
server = WEBrick::HTTPServer.new(Port: 1234)
server.mount_proc('/') { |req, res| IO.popen('pbcopy', 'w') { |io| io.write(req.body) } }
server.start
@jurriaan
jurriaan / benchmark_jwt.rb
Created June 16, 2015 09:12
benchmark_jwt.rb
$LOAD_PATH.unshift('./lib/')
require 'jwt'
require 'benchmark/ips'
@private_key = {}
@public_key = {}
@jwt = {}
@payload = { :hello => 'world' }
def init_jwt(type, key_type)
@jurriaan
jurriaan / icmake.rb
Created October 1, 2014 15:29
Icmake version 7.21.00
require 'formula'
class Icmake < Formula
url 'http://downloads.sourceforge.net/project/icmake/icmake/7.21.00/icmake_7.21.00.orig.tar.gz'
homepage 'http://icmake.sourceforge.net/'
sha1 '57e9a00963fbca1f9a3535b2b3cc5692f9799b5b'
depends_on 'gnu-sed'
def patches
@jurriaan
jurriaan / calculate_char_width.rb
Created April 3, 2014 10:31
A way to correctly determine the width of characters in Microsoft Excel
$widths = {1 => 68.28515625,
2 => 35,
3 => 112.7109375,
4 => 57.140625,
5 => 134.85546875,
6 => 68.28515625,
7 => 157,
8 => 79.42578125,
9 => 157,
10 => 79.42578125,
require 'open-uri'
require 'rubocop'
require 'tmpdir'
url = 'https://raw.github.com/bbatsov/ruby-style-guide/master/README.md'
data = open(url).read
code_blocks = data.scan(/```ruby[\r\n]+(.*?)```/mi)
puts "Found #{code_blocks.length} code blocks"
Routes loaded, stack:
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:420:in `instance_exec'
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:420:in `block in with_default_scope'
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:618:in `scope'
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:419:in `with_default_scope'
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:287:in `eval_block'
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:295:in `block in finalize!'
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:295:in `each'
/usr/local/Cellar/ruby/2.0.0-p0/lib/r
@jurriaan
jurriaan / string.format.js
Created July 25, 2011 13:20 — forked from tbranyen/string.format.js
safer string formatting
// Inspired by http://bit.ly/juSAWl
// Augment String.prototype to allow for easier formatting. This implementation
// doesn't completely destroy any existing String.prototype.format functions,
// and will stringify objects/arrays.
String.prototype.format = function(i, safe, arg) {
function format() {
var str = this, len = arguments.length+1;
// For each {0} {1} {n...} replace with the argument in that position. If