Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile

Keybase proof

I hereby claim:

  • I am sideshowcoder on github.
  • I am sideshowcoder (https://keybase.io/sideshowcoder) on keybase.
  • I have a public key ASAEE-dQHXaxnF5kXmIlTg3XB_YoqdRpORJs-L2ImDIItgo

To claim this, I am signing this object:

@sideshowcoder
sideshowcoder / awesome_report_test.rb
Last active May 12, 2018 01:51
Helper for testing rake tasks in rails using minitest.
require 'test_helper'
# testing rake task app:awesome_report
# defined in file lib/tasks/app/awesome_report.rake
describe 'App::AwesomeReportTaskTest' do
it 'generates the awesomeness report' do
subject.invoke
assert File.exists?('awesomeness_report.csv')
end
@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 / 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)
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \w\$(parse_git_branch) \\$ "
@sideshowcoder
sideshowcoder / batch_insert.js
Last active September 1, 2017 12:14
Mass insert documents in Couchbase
var couchbase = require("couchbase")
var async = require("async")
var db = new couchbase.Connection({})
// create insert function which expects just a callback
function insertFormObject(object) {
return function (cb) {
db.set(object._id, object.value, cb)
}
;; automatically open a file as sudo unless we have permission to write it
;; already, after all this is my machine and I can do what I want!
(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))))
@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))))))
@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 / 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)))