Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
@sideshowcoder
sideshowcoder / calculator.fsx
Created September 5, 2016 21:48
F# Reverse Polish notation (RPN) Calculator
open System
type Token =
| Number of int
| UnaryOperator of (int -> int -> int)
let tryCharToToken a =
match (Int32.TryParse a) with
| (true, num) -> Some (Number num)
| (false, _) ->
@sideshowcoder
sideshowcoder / transfer_huge_file.rb
Last active July 14, 2016 12:20
Transfer a huge file over a flaky SCP connection
# On the server side split the core file into 50M chunks naming them core.0000000000 etc.
# $ split -a 10 -b 50M -d core core.
# reassamble on the other side via
# $ cat core.* > core
chunk_count = 538
root_name = "core." # name on server is 'core.00001 etc'
host = "myhost.com"
path = "/tmp"
@sideshowcoder
sideshowcoder / docker-machine-setup.el
Created June 13, 2016 10:12
Setup docker-machine env for Emacs to use
(defun setup-docker-machine-env ()
" Parse the output of docker-machine env and setup the needed env vars"
(interactive)
(mapcar
(lambda (e)
(if e
(let ((var-value (split-string-and-unquote (car e) "=")))
(setenv (s-chop-suffix "=" (car var-value)) (car (cdr var-value))))))
(mapcar
(lambda (e)
@sideshowcoder
sideshowcoder / emacs-github-pr.el
Created April 22, 2016 11:10
Visit and Create GitHub PRs quickly from Emacs
;; URL for current branch PR should
;; look like this:
;; https://github.com/sideshowcoder/tbrokersetip/compare/master...sideshowcoder-patch-1?quick_pull=1
;; (requires magit)
(defun coder/string-remove-until (string seperator)
(nth 1 (split-string string seperator)))
(defun coder/string-remove-after (string seperator)
(nth 0 (split-string string seperator)))
@sideshowcoder
sideshowcoder / switch-github-user.el
Created February 24, 2016 22:45
Switching github users when using magit
;; make sure we always use the correct user for git when using magit, and save it off for later as well
;; in the local user property for the repo
(require 'subr-x)
(defun yammer-git-repo-p ()
(string-match "int.yammer.com" (shell-command-to-string "git config --get remote.origin.url")))
(defun yammer-git-property (prop)
(string-trim (shell-command-to-string (format "git config --get %s" prop))))
require "pry"
def chop number, numbers, acc = 0
return -1 if numbers.nil? || numbers.empty?
pivot_pos = (numbers.size / 2)
pivot = numbers[pivot_pos]
return pivot_pos + acc if pivot == number
smaller = numbers.slice(0, pivot_pos)
a = [1,2,3]
b = [4,5,6]
# ruby can be quite functional sadly we don't have a sum by default
sum = lambda { |args| args.reduce(:+) }
# with this we can do
a.zip(b).map(&sum)
# extending does not change much
c = [7,8,9]
@sideshowcoder
sideshowcoder / process_ctrl.rb
Created December 30, 2015 13:28
Setting the ruby process name
class ProcessCtrl
module LibC
PR_SET_NAME = 15
extend FFI::Library
ffi_lib "c"
attach_function :prctl, [:int, :pointer, :long, :long, :long], :int
end
class << self
@sideshowcoder
sideshowcoder / .gitconfig
Created November 17, 2015 20:31
my aliases
[alias]
a = add
ac = add -p
c = commit
co = checkout
p = push
pr = pull-request
s = status
serve = daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/
l = log --oneline
MAX_MEM=50000
for pid in $(ps ax|grep 'unicorn_rails worker'|awk 'NR>1 {print l} {l=$1}'); do
test $(cat "/proc/$pid/status" | grep "VmSize:" | sed -re s,VmSize:\\s+,, | cut -d" " -f1) -gt $MAX_MEM && kill -QUIT $pid
done