Skip to content

Instantly share code, notes, and snippets.

(defadvice ido-find-file (after find-file-sudo activate)
"Find file as root if necessary."
(unless (and buffer-file-name
(file-writable-p buffer-file-name))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
@sw1nn
sw1nn / 3dprinter-slic3r.c
Last active March 4, 2017 23:35
wrapper for sli3cr.exe to allow calling from fusion 360.
#include <process.h>
#include <direct.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
/*
* This is the location Prusa installs their version of Slic3r, edit as appropriate
;; Based on https://clojuredocs.org/clojure.core/condp#example-542692cbc026201cdc326bea
(defn parse-arg [s]
(condp (comp next re-matches) s
#"([+-])(\w+)" :>> (fn [[f k]] [(keyword k) (= f "+")])
#"(\w+)=(\w+)" :>> (fn [[k v]] [(keyword k) v])
(throw (IllegalArgumentException. s))))
(parse-arg "+foo") ;=> [:foo true]
(parse-arg "-foo") ;=> [:foo false]

Git hooks suggestions

Problem Statement

With a centralized workflow we expect the branch master to be what's deployed /deployable to production. Changes are implemented on feature branches (typically named feature/<feature-name>) and merged into master via Github Pull request UI workflow.

This works fine, but occasionally a developer can make an error and push to master. We'd like to put some additional checks in place to protect against that.

Git version 1.9.x vs version 2.x.x

@sw1nn
sw1nn / docker logs weave
Created December 15, 2014 16:26
docker weave clean slate problems
======= i-f3937f14 =======
weave 2014/12/15 16:21:09.583298 [/home/weave/weaver -iface ethwe -wait 5 -name 7a:63:a6:ae:28:f4 10.23.1.93 10.23.1.94 10.23.1.62 10.23.1.63 10.23.1.65 10.23.1.64 10.23.1.92]
weave 2014/12/15 16:21:10.584473 Our name is 7a:63:a6:ae:28:f4
weave 2014/12/15 16:21:10.657163 Sniffing traffic on &{29 65535 ethwe d6:e1:22:b7:57:ae up|broadcast|multicast}
weave 2014/12/15 16:21:10.657253 Discovered our MAC d6:e1:22:b7:57:ae
weave 2014/12/15 16:21:10.657442 Attempting connection to 10.23.1.93:6783
weave 2014/12/15 16:21:10.657497 Attempting connection to 10.23.1.94:6783
weave 2014/12/15 16:21:10.657599 Attempting connection to 10.23.1.62:6783
====================== i-9710f170 =======================
Our name is 7a:fb:75:5d:01:0c
Sniffing traffic on &{11 65535 ethwe a2:28:e8:f3:ba:c2 up|broadcast|multicast}
MACs:
4a:e9:81:c0:9a:20 -> 7a:fb:75:5d:01:0c (2014-12-11 21:52:39.020285318 +0000 UTC)
Peers:
Peer 7a:f5:01:d2:ff:ef (v9) (UID 14018143749851713672)
-> 7a:fb:75:5d:01:0c [10.23.1.44:36932]
@sw1nn
sw1nn / docker-logs-weave-ev01-host
Last active August 29, 2015 14:11
weave network connectivity loss
weave 2014/12/11 16:02:32.978501 [/home/weave/weaver -iface ethwe -wait 5 -name 7a:fb:75:5d:01:0c 10.23.1.43 10.23.1.45 10.23.1.233 10.23.1.232 10.23.1.39 10.23.1.47 10.23.1.231 10.23.1.208 10.23.1.46 10.23.1.41 10.23.1.42 10.23.1.40]
weave 2014/12/11 16:02:32.979248 Our name is 7a:fb:75:5d:01:0c
weave 2014/12/11 16:02:32.999295 Sniffing traffic on &{11 65535 ethwe a2:28:e8:f3:ba:c2 up|broadcast|multicast}
weave 2014/12/11 16:02:32.999413 Discovered our MAC a2:28:e8:f3:ba:c2
weave 2014/12/11 16:02:33.017261 Attempting connection to 10.23.1.43:6783
weave 2014/12/11 16:02:33.017452 Attempting connection to 10.23.1.45:6783
weave 2014/12/11 16:02:33.017494 Attempting connection to 10.23.1.233:6783
weave 2014/12/11 16:02:33.017532 Attempting connection to 10.23.1.232:6783
weave 2014/12/11 16:02:33.017614 Attempting connection to 10.23.1.39:6783
weave 2014/12/11 16:02:33.017658 Attempting connection to 10.23.1.47:6783
$ weave status
Our name is 7a:9d:92:2a:9d:0f
Sniffing traffic on &{9 65535 ethwe b2:e1:20:b6:c7:e3 up|broadcast|multicast}
MACs:
be:db:12:1d:91:1c -> 7a:e9:b4:b3:d1:c4 (2014-12-11 14:19:26.0650811 +0000 UTC)
42:b1:20:60:b3:bb -> 7a:9d:92:2a:9d:0f (2014-12-11 14:20:05.29314343 +0000 UTC)
5e:54:04:ac:27:c2 -> 7a:17:f8:60:65:d1 (2014-12-11 14:19:32.976367503 +0000 UTC)
9a:24:71:cd:3e:b9 -> 7a:79:89:9f:94:1d (2014-12-11 14:20:02.348941936 +0000 UTC)
66:17:8a:0e:07:c3 -> 7a:cc:69:40:f9:d6 (2014-12-11 14:19:42.2881824 +0000 UTC)
7e:44:b1:89:e4:78 -> 7a:44:69:3d:22:05 (2014-12-11 14:19:55.461416483 +0000 UTC)
weave 2014/12/11 13:19:55.012864 Attempting connection to 10.23.1.192:6783
weave 2014/12/11 13:19:55.013569 dial tcp4 10.23.1.192:6783: connection refused
weave 2014/12/11 13:19:57.635682 Attempting connection to 10.23.1.185:6783
weave 2014/12/11 13:19:57.636172 dial tcp4 10.23.1.185:6783: connection refused
weave 2014/12/11 13:20:07.710553 ->[10.23.1.189:40351] encountered error during handshake: Already have connection to 7a:17:f8:60:65:d1 at 10.23.1.189:6783
weave 2014/12/11 13:20:16.088137 Attempting connection to 10.23.1.188:6783
weave 2014/12/11 13:20:16.088690 dial tcp4 10.23.1.188:6783: connection refused
weave 2014/12/11 13:20:19.231901 ->[10.23.1.193:43468] encountered error during handshake: Already have connection to 7a:79:89:9f:94:1d at 10.23.1.193:6783
weave 2014/12/11 13:20:21.558148 Attempting connection to 10.23.1.192:6783
weave 2014/12/11 13:20:21.558796 dial tcp4 10.23.1.192:6783: connection refused
user> *clojure-version*
{:major 1, :minor 7, :incremental 0, :qualifier "alpha2"}
user> (defn colsum [f1]
(let [acc (atom (repeat 0))]
(fn
([] (f1))
([result] (f1 (vec @acc)))
([result input]
(swap! acc #(map + %1 %2) input)
result))))