Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@folkertdev
folkertdev / 0_reuse_code.js
Created August 8, 2014 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@folkertdev
folkertdev / chrome-reload.sh
Created July 3, 2015 19:56
Reload current chrome tab on a file change
#!/bin/bash
# inspired by
# http://linux.die.net/man/1/inotifywait
# http://razius.com/articles/auto-refreshing-google-chrome-on-file-changes/
# http://unix.stackexchange.com/questions/37258/refresh-reload-active-browser-tab-from-command-line
# Usage:
# ./chrome-refresh.sh /folder/to/watch /some/folder/file_to_watch.html
TIME_FORMAT='%F %H:%M'
@folkertdev
folkertdev / resample.py
Last active August 29, 2015 14:27
An improvement idea for the Freestyle resample method. Improvements include inline vector operations, next(it) for pairwise iteration and a for instead of while loop.
# pairwise is defined in utils.py and a very handy function
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return zip(a, b)
def resample(stroke, sampling=5.0):
new_vertices = []
for a, b in pairwise(stroke):
new_vertices.append(a)
@folkertdev
folkertdev / newtonPolynomial.py
Created September 27, 2015 13:59
A sympy-based newton polynomial constructor.
"""
A sympy-based newton polynomial constructor.
Given a set of function inputs and outputs, the newtonPolynomial function will construct an
expression that for every input gives the corresponding output. For intermediate values,
the polynomial interpolates (giving varying results based on the shape of your input).
This is useful when the result needs to be used outside of Python, because the
expression can easily be copied. To convert the expression to a python function object,
use sympy.lambdify.
@folkertdev
folkertdev / lagrangePolynomial.py
Created September 27, 2015 14:12
A sympy-based Lagrange polynomial constructor
"""
A sympy-based Lagrange polynomial constructor.
Given a set of function inputs and outputs, the lagrangePolynomial function will construct an
expression that for every input gives the corresponding output. For intermediate values,
the polynomial interpolates (giving varying results based on the shape of your input).
This is useful when the result needs to be used outside of Python, because the
expression can easily be copied. To convert the expression to a python function object,
use sympy.lambdify.
"""
@folkertdev
folkertdev / tuple.cpp
Created May 24, 2016 18:36
C++ iterator to Python tuple
// from the Blender Freestyle code
static PyObject *Stroke_viewedges_begin(BPy_Stroke *self)
{
PyObject *output = PyTuple_New(self->s->viewedges_size());
std::vector<ViewEdge*>::iterator ve_it = self->s->viewedges_begin(), ve_end = self->s->viewedges_end();
for (unsigned int i = 0; ve_it != ve_end; ++ve_it, ++i) {
PyTuple_SET_ITEM(output, i, BPy_ViewEdge_from_ViewEdge(*(*ve_it)));
}
@folkertdev
folkertdev / predicate.py
Created May 24, 2016 18:37
Generator function as a Freestyle predicate
def pyVertexNatureUP0D(nature):
""" Generator function as predicate. about 50% slower, but it works """
while True:
print("doing work")
inter = yield
if inter is None:
continue
yield bool(inter.object.nature & nature)
it = Interface0DIterator(stroke)
@folkertdev
folkertdev / Main.elm
Created July 14, 2016 14:24
Handling a list of OutMsg the nice way
-- Effective code. Nice and short
let
updateModel newEditor (Model generic _) =
Model generic (EditorView { apiToken = apiToken, staticToken = staticToken, editor = newEditor })
in
Editor.State.update childMsg editor
|> mapChildCmd ChildEditorAction
|> outMsgUpdate updateModel editorOutMsg model
-- The magic that makes it possible
@folkertdev
folkertdev / Test7.hs
Created September 25, 2016 12:39
Justitia test 7
import Data.List
original =
[ "..0...0.....1."
, "1....0....0.11"
, "...1...0......"
, "1...0........."
, "......0..1.0.0"
, "1..11..1..1..."
, "........0....."
, "1.1..1...11..."
@folkertdev
folkertdev / Main.elm
Last active January 26, 2017 20:56
Keep track of the number of outstanding http requests
-- Read more about this program in the official Elm guide:
-- https://guide.elm-lang.org/architecture/effects/http.html
module Main exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Http