Skip to content

Instantly share code, notes, and snippets.

View ordovician's full-sized avatar

Erik Engheim ordovician

View GitHub Profile
@ordovician
ordovician / dump-pixmap.cpp
Created January 9, 2019 11:37
[Dump QPixmap to File] This is to help debug code where pixmaps are created #qt
#include <QtCore/QFile>
#include <QtCore/QDir>
/// Store pixmap in home directory as .png file
static void
DumpPixmapToFile(const QPixmap &pixmap) {
QString filepath = QDir::home().filePath("debug-pattern.png");
pixmap.save(filepath, "PNG");
}
@ordovician
ordovician / rm-trailing-whitespace.sh
Created October 18, 2018 09:25
[Remove trailing whitespace] Allows you to do through all files in subdirecttory and remove any occurance of trailing whitespace. Make sure you got these files under version control as it will do in place replacement. #unix #shell #sed
find . -type f | xargs sed -i 's/[ \t]*$//'
@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 / 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 / .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 / 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 / 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 / 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 / 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
@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