Skip to content

Instantly share code, notes, and snippets.

View dsabanin's full-sized avatar
💭
It's Complicated

Dmitry Sabanin dsabanin

💭
It's Complicated
View GitHub Profile
(use 'ring.adapter.simpleweb)
;; Define a basic ring handler
(defn handler [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello world from SimpleWeb"})
;; Start the server on the specified port, returning a connection
(def connection (run-simpleweb handler {:port 8080}))
@dsabanin
dsabanin / gist:5860527
Created June 25, 2013 17:36
Useful strace command
strace -qfFxv -s 1024 -p PROCESS-PID
(def first (fn [first]
(fn [second] first)))
(def second (fn [first]
(fn [second] second)))
(def make-pair (fn [first] (fn [second] (fn [func] ((func first) second)))))
(def TRUE first)
(def FALSE second)
def diffs(repo, from, to)
repo.call_git("diff ?..?", from, to).stdout.
strip.
split(/diff --git.*?$/).
map(&:strip).
uniq.
map { |d| d.blank? ? nil : d }.
compact.
map { |d| [diff_head(d), d] }
end
@dsabanin
dsabanin / raise-on-match.clj
Last active December 24, 2015 00:39
raise-on-match
(defmacro raise-on-match
[matches & body]
(loop [matches (->> matches (partition-all 2) (reverse))
res `(do ~@body)]
(when matches
(recur (rest matches)
`(raise-on ~(first matches) ~res)))
res))
;; Usage
@dsabanin
dsabanin / port_redirect.sh
Created May 23, 2014 14:55
Script for setting up redirect for a local port to a remote host's port (root or sudo needed)
#!/bin/sh
TARGET_HOST=9.9.9.9
TARGET_PORT=22
PROXY_PORT=23
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $PROXY_PORT -j DNAT --to $TARGET_HOST:$TARGET_PORT
iptables -t nat -A PREROUTING -p tcp --dport $PROXY_PORT -j DNAT --to $TARGET_HOST:$TARGET_PORT
@dsabanin
dsabanin / deploy.sh
Last active August 29, 2015 14:07
Tiny capistrano-like script for dploy.io
# Execute as ./deploy.sh /data/project 19851203123502
# It will deploy final release as a symlink from /data/project/current to /data/project/releases/19851203123502
BASE=$1
TIMESTAMP=$2
RELEASE=$BASE/releases/$TIMESTAMP
mkdir -p $BASE/releases $BASE/shared $BASE/logs
cp -al $BASE/deploy-cache $RELEASE
@dsabanin
dsabanin / keybase.md
Created July 5, 2016 14:28
Keybase proof

Keybase proof

I hereby claim:

  • I am dsabanin on github.
  • I am dsabanin (https://keybase.io/dsabanin) on keybase.
  • I have a public key ASCR4oyyMHmDzrg6nI3aHvWXodl8NimeCb3qxTnv7qscywo

To claim this, I am signing this object:

@dsabanin
dsabanin / start.ts
Last active April 18, 2023 09:08
Electron auto-update startup fix
// The idea here is to make sure that ShipIt process that copies the updated app exits
// before we launch the new version. The code below checks if the update is still in progress,
// which means that we are running the old app still, it keeps checking until ShipIt exits and restarts
// the app hoping that a new version will start up at that time.
//
// "find-process": "~1.2.1",
import findProcess from 'find-process';
const BUNDLE_NAME = 'com.myorganization.bundleName';
const SHIP_IT_BINARY = 'ShipIt';
@dsabanin
dsabanin / enable-xcode-debug-menu.sh
Last active November 7, 2022 16:17
Enable internal Xcode debug menu in Xcode 11
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode
sudo touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist
# Don't forget to restart Xcode