Skip to content

Instantly share code, notes, and snippets.

@niclasnilsson
niclasnilsson / nav_example.cljc
Last active October 8, 2022 16:09
clojure nav
(ns nav-example
"An example of how clojure.datafy/nav can be used."
(:require
[clojure.core.protocols :as p]
[clojure.datafy :as d]
[clojure.set :as set]))
(defn submap?
"Checks whether a is a submap of b"
@niclasnilsson
niclasnilsson / config
Last active June 17, 2021 13:30
Example ~/.ssh/config for dealing with JSch and public key authentication with encrypted (password protected) keys.
# Example ~/.ssh/config for dealing with JSch problems regarding
# ssh public key authentication with encrypted (password protected) keys.
#
# First, a problem description and a couple of solutions that worked for me,
# (in March 2018 on MacOS High Sierra) and in the bottom youäll find an example
# config that doesn't interfere with JSch's use of the ssh-agent.
#
#
# Problem description:
# --------------------
@niclasnilsson
niclasnilsson / gist:db63c5110e7a0b53cc98
Created May 21, 2015 06:54
The Vietnamese third grade math problem in Ruby
# The equation
def equation(a, b, c, d, e, f, g, h, i)
a + 13 * b / c + d + 12 * e - f - 11 + g * h / i - 10
end
# The brute force
def solutions(*numbers)
numbers.
permutation.
map { |nums| [nums, equation(*nums)] }.
require 'clean_assert'
def add_drinking_person(name, age)
assert / "name != nil" / "not name.empty?" / "age >= 21"
puts "Adding '#{name}' of age #{age} to the list of drinkers"
# And some code to do it...
end
add_drinking_person("Niclas", 17)
# Gives:
@niclasnilsson
niclasnilsson / gist:1251754
Created September 29, 2011 19:53
Log file: Deploying the EngineYard ToDo app on JRuby 1.6.4/Trinidad.
:: running ssh -i /home/deploy/.ssh/internal -o StrictHostKeyChecking=no -o PasswordAuthentication=no deploy@ec2-50-17-6-248.compute-1.amazonaws.com '/usr/local/ey_resin/ruby/bin/gem list engineyard-serverside | grep "engineyard-serverside" | egrep -q '\''1\.4\.16[,)]'\'
:: running git clone -q https://github.com/engineyard/todo.git /data/todo/shared/cached-copy 2>&1
~> Deploying revision 00fa4e7 Another temp model.
:: running git checkout -q '00fa4e7297f99b3a096c0f7b02ec03800aa21eff'
:: running git submodule sync
:: running git submodule update --init
:: running git clean -dfq
~> Pushing code to all servers
:: running ssh -i /home/deploy/.ssh/internal -o StrictHostKeyChecking=no -o PasswordAuthentication=no deploy@ec2-50-17-6-248.compute-1.amazonaws.com 'mkdir -p /data/todo/shared/cached-copy'
:: running rsync --delete -aq -e "ssh -i /home/deploy/.ssh/internal -o StrictHostKeyChecking=no -o PasswordAuthentication=no" /data/todo/shared/cached-copy/ deploy@ec2-50-17-6-248.compute-1.amazonaws.com:/data/todo/sha
@niclasnilsson
niclasnilsson / shorten2.rb
Created February 17, 2011 08:00
Second stab at shortening a sting. Is this brute enough?
$cache = {}
def shorten(s, ws)
$cache[s] ||= ws.flat_map { |w|
a = s.split(w, -1)
(0..a.size-1).map { |p|
ns = a[0..p].join(w) + a[p+1..-1].join(w)
ns.size < s.size ? shorten(ns, ws) : s
}
}.min_by { |s| s.size }