Skip to content

Instantly share code, notes, and snippets.

View simcap's full-sized avatar

Simon simcap

View GitHub Profile
@simcap
simcap / cheatsheet.txt
Created February 4, 2016 14:27
Cheatsheet: systemd & syslog to remote syslog
sudo vim /etc/systemd/journald.conf
less /var/log/syslog
sudo vim /etc/rsyslog.conf
sudo systemctl status rsyslog
- Syslog conf on sender side:
# Provides TCP forwarding. But the current server runs on UDP
*.* @@10.0.0.51:514
@simcap
simcap / godeploy.sh
Last active January 27, 2016 17:05
Deploy go appa by convention
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: first argument is the machine alias on which you want to deploy"
exit 1
fi
HOST_ALIAS=$1
PROJECT_NAME=${PWD##*/} # basename of current dir
if ! [ -z $2 ]; then
@simcap
simcap / vegeta.go
Last active August 8, 2020 17:26
Vegeta example
package main
import (
"bufio"
"encoding/json"
"fmt"
"net/url"
"net/http"
"os"
"time"
@simcap
simcap / run.sh
Last active August 29, 2015 14:26
Run Kafka
# https://godoc.org/github.com/Shopify/sarama
# https://github.com/spotify/docker-kafka
wget http://apache.websitebeheerjd.nl/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz
tar xvzf kafka_2.11-0.8.2.1.tgz
cd kafka_2.11-0.8.2.1
# With docker installed
docker run -p 2181:2181 -p 9092:9092 --env ADVERTISED_HOST=`boot2docker ip` --env ADVERTISED_PORT=9092 spotify/kafka
@simcap
simcap / der.js
Created May 27, 2015 20:53
Generate DER encoding from known ECDSA private key in JS
"use strict";
var ECKey = require('eckey')
var fs = require('fs')
var seed = process.argv[2]
var bytes = new Uint8Array(32);
for (var i = 0; i < seed.length; i += 2) {
@simcap
simcap / der.go
Created May 27, 2015 20:51
Generate DER encoding from known ECDSA private key in Golang
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"flag"
"fmt"
"io/ioutil"
@simcap
simcap / correct_version.rb
Last active August 29, 2015 14:10
Returns the most likely version among multiple given hashes
#!/usr/bin/ruby
# Run with
# $ ruby -r minitest/autorun $PROGRAM_NAME
#
# Returns the correct version among multiple given
# hashes. In other words, which hash is the one
# that most ressemble the other hashes ?
#
# First a Hash has to be able to say
# how similar it is to another one
@simcap
simcap / immutable_struct.rb
Last active August 29, 2015 14:09
Defining a fast immutable Struct
# Defining a fast immutable struct while
# keeping Struct value object behaviour
class ImmutableStruct < Struct
undef []=, send
def self.inherited(subclass)
subclass.instance_methods.grep(/\w=/) do |setter|
undef_method setter
end
@simcap
simcap / salad.rb
Last active August 29, 2015 14:06
A good intermediary for internal only access of instance variables
# A good intermediary for internal-only access of instance variables
# Here the example is with the access on the 'sauce' instance variable
class Salad
def initialize(sauce)
@sauce = sauce
end
attr_reader :sauce
@simcap
simcap / no_struct_for_poro.rb
Last active August 29, 2015 14:05
Why I do not like Struct for PORO (Plain Old Ruby Object) ?
Customer = Struct.new(:name, :address)
c = Customer.new('john') # Do not validate construction
c.name # => 'john'
c.address # => nil
c['name'] # => 'john'
# Extra unneeded API to access your property
c['name'] = 'robert'