Skip to content

Instantly share code, notes, and snippets.

View mlb-'s full-sized avatar

Matthew Batema mlb-

View GitHub Profile
@artizirk
artizirk / export existing ssh private key to opengpg card.md
Last active June 19, 2024 21:50
Export existing private ssh key to OpenPGP card or Yubikey

Export existing private ssh key to OpenPGP card or Yubikey

Before you begin

This will only work with OpenPGP v2.0 or newer or with PIV cards. Your existing ssh key has to be in a format that is supported by your opengpg card. For example my the OpenPGP V2.1 Card from FLOSS Shop supports only 2048 bit RSA keys. RSA exponent should be 65537, Putty and old OpenSSH releases use different expnent that for example Yubikey does not support.

Required software

@featheredtoast
featheredtoast / AutowireHelper.java
Created November 19, 2016 22:11
spring autowire stuff
/**
* Helper class which is able to autowire a specified class. It holds a static reference to the {@link org
* .springframework.context.ApplicationContext}.
*/
@Component
public final class AutowireHelper implements ApplicationContextAware {
private static final AutowireHelper INSTANCE = new AutowireHelper();
private static ApplicationContext applicationContext;
@johanandren
johanandren / SimplePartitionSample.scala
Created July 26, 2016 08:25
Sample of using partition to split up incoming elements over multiple outgoing streams
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import scala.io.StdIn
import scala.util.Random
object SimplePartitionSample extends App {
implicit val system = ActorSystem()
(defn happy-numbers
[n]
(letfn [(next-happy [n]
(->> (str n)
(partition 1 1)
(map first)
(take-while #(not (= \. %)))
(map (comp #(Math/pow % 2) read-string str))
(reduce +)))
(repeats? [coll]
(defn gol
"Returns the next generation for a given game of life board"
[b]
(let [cells (for [x (range (count (first b)))
y (range (count b))]
[x y])
is-alive? (fn [[x y]]
(= \# (get-in b [x y])))
find-surrounding-live (fn [[cellx celly]]
(for [x (range (dec cellx) (+ 2 cellx))
(defn tic-tac
[b]
(let [winning-moves [[[0 0] [0 1] [0 2]]
[[1 0] [1 1] [1 2]]
[[2 0] [2 1] [2 2]]
[[0 0] [1 0] [2 0]]
[[0 1] [1 1] [2 1]]
[[0 2] [1 2] [2 2]]
[[0 0] [1 1] [2 2]]
[[2 0] [1 1] [0 2]]]
@featheredtoast
featheredtoast / longestsubstring.clj
Last active October 2, 2015 23:52
Just because I apparently can't think in an interview room.
(defn findSubstring
"Finds the longest substring"
[s]
(->> (range (dec (count s)) 0 -1)
(map #(->> s
(partition % 1)
(map (partial apply str))
(getSubstring)))
(drop-while nil?)
first))
@featheredtoast
featheredtoast / gist:106209adb0ad1ddf8f86
Created November 20, 2014 02:40
ELK elasticsearch logrotate
#!/bin/sh
for i in 30 31 32 33 34 35
do
logdate=$(date --date='TZ="UTC" 09:00 '${i}' days ago' +"%Y.%m.%d")
curl -XDELETE "http://localhost:9200/logstash-${logdate}"
done
@nox
nox / gist:3981420
Created October 30, 2012 16:43
wtf is sofs useful for
1> ParentChildRel = sofs:relation([{michel,gertrude},{robert,mickael},{brigitte,gertrude},{brigitte,sophia}], [{parent, child}]).
{'Set',[{brigitte,gertrude},
{brigitte,sophia},
{michel,gertrude},
{robert,mickael}],
{parent,child}}
2> ParentChildrenRel = sofs:relation_to_family(ParentChildRel).
{'Set',[{brigitte,[gertrude,sophia]},
{michel,[gertrude]},
{robert,[mickael]}],
@stolen
stolen / gs_up.erl
Created September 27, 2012 09:33
gen_server with self-upgrading state prototype
-module(gs_up).
-export([init/1, handle_call/3, terminate/2]).
-record(state, {
own_fields,
field1,
field2,
field3
}).