Skip to content

Instantly share code, notes, and snippets.

View moser's full-sized avatar

Martin Vielsmaier moser

View GitHub Profile
@moser
moser / parse_text_interpolation.py
Last active September 22, 2022 09:55
parse_text_interpolation.py
"""
pip install parsimonious
"""
import dataclasses as _dc
from parsimonious.grammar import Grammar
from parsimonious.nodes import NodeVisitor
TEXT = """
Here are some {variable}s. I don't care about spaces in the { interpolations}.
"""
Reads GPS data from gpsfeed+ (https://sourceforge.net/projects/gpsfeed/), adds
some fake FLARM and OpenVario data and sends this on to XCSoar.
"""
import socket
import functools
import time
import datetime as dt
@moser
moser / pyplot_histogram_on_axes.ipynb
Last active March 23, 2018 09:35
Pyplot: Histogram on X/Y axis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am moser on github.
  • I am moser (https://keybase.io/moser) on keybase.
  • I have a public key whose fingerprint is B068 15D6 ED68 61B2 285E FA44 561F E468 D14F EFDE

To claim this, I am signing this object:

@moser
moser / printCurrentStackTrace
Created October 21, 2010 16:29
Print the current stack trace
public void printCurrentStackTrace() {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
for(int i= 2; i < elements.length; i++) { //2 to remove Thread#getStackTrace and this method
System.out.println(elements[i]);
}
}
@moser
moser / solve.hs
Created September 22, 2015 21:30
Solving a minotauros cube in haskell: see blog post: http://moserei.de/2015/09/22/haskell-minotauros-cube.html
import Data.Maybe
import Data.List
import qualified Data.Set as Set
type Point = (Int, Int, Int)
type Shape = Set.Set Point
keys = [1..3]
allKeys = [(x, y, z) | x <- keys, y <- keys, z <- keys]
# defined in my spec_helper
# requires mocha
# needed because
# mock() { expects(:foo).with(:bar, anything) }
# does not work. (fails with "Mocha::ExpectationError: unexpected invocation: #<Mock:0x1d8>.anything()")
# Usage:
# mock_block() do |m|
# m.expects(:foo).with(:bar, anything)
# end
def mock_block(&block)
@moser
moser / AR association accessor with string acceptance
Created April 2, 2009 23:11
AR association accessor with string acceptance
# Host is a simple two row model: id, name
# I think the check whether a host with the given
# name exists, should go right there.
# Still it accepts normal host objects.
# A big advantage over Host.find_or_create is,
# that I can use "host" as a normal text field in
# my forms and it's all done automatically.
class MyModel < ActiveRecord::Base
belongs_to :host
@moser
moser / Rails model default order.rb
Created March 5, 2009 10:58
replaced by default_scope
Class Model < ActiveRecord::Base
def self.find(*args)
order = {:order => "name ASC"}
if args.length <= 1
args << order
else
args[1] = order.merge(args[1])
end
super
@moser
moser / gist:9949291
Created April 3, 2014 06:32
Poor man's autotest for any language
while true; do inotifywait -e modify file1 my_test_file1 ... && MY_TEST_COMMAND; done