Skip to content

Instantly share code, notes, and snippets.

View ordovician's full-sized avatar

Erik Engheim ordovician

View GitHub Profile
@ordovician
ordovician / git-change-history.rb
Created November 5, 2012 19:24
Change git history without modifying the tree blobs pointed to by commits
#! /usr/bin/env ruby
if ARGV.empty?
puts "Usage: git-change-history base [new-branch-name]"
puts " a list of SHA-1 for commits are given on STDIN. These are commits are added onto base"
puts "Example:"
puts " git log --pretty=\"%H\" master | git-change-history.rb base mynewbranch"
puts ""
puts "Use 'git log --pretty=\"%H %s\"' to test if you have the right SHA-1 commit hashes listed"
exit
@ordovician
ordovician / fish_prompt.fish
Last active October 3, 2018 23:22
[fish current directory] Set the prompt in the fish shell to a minimalistic "currentdir $ " Where currendir is the last directory in current working directory
function fish_prompt
echo -n '['
set_color $fish_color_cwd
echo -n (basename $PWD)
set_color normal
echo -n '] $ '
end
@ordovician
ordovician / config.fish
Created May 18, 2013 07:02
My configuration file for the fish shell
# Make the blue color for directories more readable
set -x LSCOLORS Exfxcxdxbxegedabagacad
# this is needed to avoid strange python stack backtrace complaining about UTF-8 when
# running sphinx. Found it by googling
set -x LC_ALL en_US.UTF-8
set -x LANG en_US.UTF-8
set -x JULIA_EDITOR textmate
# so our brew install override the commands from the system
@ordovician
ordovician / .gitconfig
Last active October 3, 2018 23:21
[Pretty git logs] Pretty logs in git and support for using sourcetree for merging. From https://coderwall.com/p/euwpig?i=3&p=1&t=git #git #config
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
@ordovician
ordovician / CongruenceModulo.jl
Last active October 3, 2018 23:17
[CongruenceModulo] Functions I made for solving problems in the Khan Academy excercises on Congruence Modulo. Usefull stuff to understand when learning about cryptograpy, like the RSA algorithm used in SSL/TSL as used in HTTPS. If two values A and B gives the same result when doing mod(A, C) and mod(B, C) then they are in the same equivalence cl…
# check if A is congruent to B modulo C.
in_same_equivalence_class(A, B, C) = mod(A, C) == mod(B, C)
# find all X in Xs where X is congruent to B modulo C
function find_numbers_in_same_equivalence_class(A, C, Xs)
r = mod(A, C)
filter(X->mod(X,C) == r, Xs)
end
@ordovician
ordovician / EquivalenceRelations.jl
Last active January 2, 2016 20:29
Equivalence Relations in modulo aritmetic.
mod(A, C) == r
# then
mod(A + k*C, C) == r
# so if
mod(A, C) == mod(B, C)
@ordovician
ordovician / gocompletion.jl
Last active October 3, 2018 23:18
[Text Mate Bundle for Go] Method, variable and function completion for the Go language written in Julia. Put this in a TextMate bundle. Currently too slow to be practical due to slow Julia startuptime #tmbundle #go #plugin
#!/usr/bin/env julia
using PList
import GoTMSupport
bundle_support = ENV["TM_BUNDLE_SUPPORT"]
dialog = ENV["DIALOG"]
gocode = ENV["TM_GOCODE"]
filepath = ENV["TM_FILEPATH"]
row = int(ENV["TM_LINE_NUMBER"])
col = int(ENV["TM_LINE_INDEX"]) + 1
@ordovician
ordovician / degrees.go
Last active October 3, 2018 23:23
[Custom number types in Go] Shows how you can utilize the fact that using the keyword "type" in Go create a new type unlike typedef in C. Allows us work with numbers without mixing up the units.
package main
import (
"fmt"
)
type Celsius float64
// Implement Stringer interface, used by %s in Printf
func (deg Celsius) String() string {
@ordovician
ordovician / settingstable.swift
Last active October 3, 2018 23:19
[Tap anywhere in text cell] How to make UITextField first responder when tapping anywhere inside a table view cell. Just like Apple's "Settings" app. #firstresponder #viewcell
class Settings : UITableViewController {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
// The cells contentview is the one containing custom added components.
if let subviews = cell?.contentView.subviews {
// Find a subview which is a UITextField. Place cursor in this textfield.
for view in subviews {
if let textfield = view as? UITextField {
@ordovician
ordovician / leppo.jl
Last active October 3, 2018 23:17
[lepton experiment] Trying of new program #experiment #hack
for i in 1:length(M)
println(i)
end