Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
@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
@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
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]
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)
@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))))
@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 / 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 / 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 / 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 / rspec_file.el
Created February 9, 2017 14:38
Run rspec on file in emacs (depends on rake.el and projectile)
(defun coder/rspec-file ()
"Run rspec on the current file and set as the compile target,
if we have zeus available than run it via zeus otherwise run it
via bundle exec rspec"
(interactive)
(projectile-with-default-dir (projectile-project-root)
(let ((command-prefix (rake--choose-command-prefix (projectile-project-root) (list :zeus "zeus test "
:bundler "bundle exec rspec "))))
(compile (concat command-prefix (coder/project-relative-current-file-path))))))