Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
@mbj
mbj / literal.rb
Created March 26, 2021 02:09
json to ruby literal
require 'json'
require 'unparser'
include Unparser::NodeHelpers
def mk_hash(hash)
s(:hash, *mk_pairs(hash))
end
def mk_pairs(hash)
@mbj
mbj / logical_implication.sql
Created October 15, 2020 15:10
Postgresql logical implication operator
CREATE FUNCTION
logical_implication(a boolean, b boolean)
RETURNS
boolean
LANGUAGE
sql
IMMUTABLE
PARALLEL SAFE
RETURNS NULL ON NULL INPUT
COST 1
@hays-hutton
hays-hutton / schema.sql
Created March 16, 2016 16:31
A Simplified Schema Example for PostgREST
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS
users (
email TEXT PRIMARY KEY CHECK ( email ~* '^.+@.+\..+$' ),
pass TEXT NOT NULL CHECK (length(pass) < 256),
role NAME NOT NULL CHECK (length(role) < 256)
);
CREATE TABLE IF NOT EXISTS
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
function f() {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1
@solnic
solnic / try_spec.rb
Created December 2, 2014 11:01
kleisli-inspired spike for handling inserts with associations in rom-rb
class Result
attr_reader :value, :error
class Success < Result
def initialize(value)
@value = value
end
def >(f)
f.call(value)
@mbj
mbj / actor.rb
Last active August 29, 2015 14:10
My minimal 135loc (stripped) actor implementation powering mutant
require 'concord'
module Actor
class ProtocolError < RuntimeError
end # ProtocolError
Undefined = Class.new do
INSPECT = 'Actor::Undefined'.freeze
def inspect
INSPECT
@mbj
mbj / input.rb
Last active August 29, 2015 14:02
mutant longest prefix match configuration spike
{"*"=>{"isolation"=>true, "selector"=>"exact"}, "Foo::Bar"=>{"isolation"=>false, "selector"=>"Foo#bar"}}
@thomasfr
thomasfr / autossh.service
Last active May 9, 2024 16:59
Systemd service for autossh
[Unit]
Description=Keeps a tunnel to 'remote.example.com' open
After=network.target
[Service]
User=autossh
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
@thomasfr
thomasfr / Git push deployment in 7 easy steps.md
Last active May 1, 2024 23:17
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@mbj
mbj / address.rb
Last active January 4, 2016 03:29
morpher
require 'morpher'
extend Morpher::NodeHelpers
class Address
include Anima.new(:street)
end
class Person
include Anima.new(:address)
end