Skip to content

Instantly share code, notes, and snippets.

View 607011's full-sized avatar
🏁
Yes, please?!

Oliver Lau 607011

🏁
Yes, please?!
View GitHub Profile
@607011
607011 / gist:6991350
Last active July 2, 2019 13:10
One iteration of the Belousov-Zhabotinsky reaction:// cell: pointer to first element of 2D array (source)cell_new: pointer to first element of 2D array (destination)// width: width of arrays// height: height of arrays// k1: influence of excited cells in neighborhood// k2: influence of activated cells in neighborhood// g: speed at which waves tra…
void BZR_iterate(int *cell, int *cell_new,
int width, int height,
int k1, int k2, int g, int n) {
int x, y, xx, yy;
int c, S, excited, active;
int v;
int c_new;
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
c = cell[x + y * (width+2)];
@607011
607011 / Channel.js
Last active August 29, 2015 13:57
Direct and indirect signalling (a.k.a. channels a.k.a. Signal & Slot a.k.a. publisher/pubscriber model)
var Channel = (function () {
var channels = {}, PREFIX = 'Channel:';
return {
connect: function (id, handler, indirect) {
indirect = indirect || false;
if (indirect) {
window.addEventListener(PREFIX + id, handler, false);
}
else {
@607011
607011 / cleartype.ps1
Created May 27, 2014 12:31
Cleartype on/off
param([bool]$enable)
$signature = @'
[DllImport("user32.dll")]
public static extern bool SystemParametersInfo(
uint uiAction,
uint uiParam,
uint pvParam,
uint fWinIni);
'@
@607011
607011 / fisher-yates-shuffle.cpp
Last active October 20, 2015 15:38
Fisher-Yates-Shuffle (shuffling of array elements)
// using Qt
QByteArray shuffled(const QByteArray &ba)
{
QByteArray result = ba;
int n = result.count();
char *c = result.data();
while (n) {
int j = qrand() % n--;
char tmp = *(c + n);
@607011
607011 / gist:6893a238c17e4ffa3707
Created February 13, 2015 12:40
BoolTranslator for boost::property_tree::ptree
#include <boost/algorithm/string/predicate.hpp>
struct BoolTranslator
{
typedef std::string internal_type;
typedef bool external_type;
// Converts a string to bool
boost::optional<external_type> get_value(const internal_type& str)
{
@607011
607011 / gist:05e09c0d0a7c5510125c
Last active August 29, 2015 14:17
Create new Windows-GUID as std::string
std::string createGUIDString(void) {
GUID guid;
HRESULT hCreateGuid = CoCreateGuid(&guid);
std::stringstream strBuf;
strBuf << std::hex << std::setw(8) << std::setfill('0')
<< guid.Data1 << "-" << guid.Data2 << "-" << guid.Data3 << "-";
for (int i = 0; i < 2; ++i)
strBuf << std::hex << std::setw(2) << std::setfill('0') << short(guid.Data4[i]);
strBuf << "-";
for (int i = 2; i < 8; ++i)
@607011
607011 / generate.cpp
Created April 21, 2015 08:30
Warming up and using the Mersenne-Twister
#include <string>
#include "mt.h"
warmupRNG();
std::uniform_int_distribution<int> rollTheDice(1, 6);
for (int i = 0; i < 1000; ++i)
std::cout << rollTheDice(gRNG()) << ", ";
@607011
607011 / 2d-arr.py
Created December 27, 2015 18:22
Generate 2D array of width w and height h
result = [a[:] for a in [[' '] * h] * w]
@607011
607011 / convert-to-video.py
Created January 28, 2016 13:13
Convert screencast from Microsoft Expression Encoder to mp4 and webm, extract a thumbnail at 75% of playtime
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, subprocess
from os import chdir
from glob import glob
FFMPEG = 'D:\\Developer\\ffmpeg.exe'
FFPROBE = 'D:\\Developer\\ffprobe.exe'
@607011
607011 / Hammering element (CSS)
Created March 24, 2016 13:34
Styles for "hammering" element
@keyframes hammer {
from,20%,53%,80%,to {
-webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0)
}
40%,43% {
-webkit-animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);