Skip to content

Instantly share code, notes, and snippets.

@tomaslibal
tomaslibal / 1x1-gif.txt
Created February 6, 2014 19:20
1x1 pixels transparent gif, base64 encoded.
data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
#include <stdio.h>
const short FLAG_1 = 1;
const short FLAG_2 = 1 << 1;
const short FLAG_3 = 1 << 2;
const short FLAG_4 = 1 << 3;
//int settings = FLAG_1|FLAG_3|FLAG_4;
int settings = 0;
@tomaslibal
tomaslibal / debugprint.h
Created July 12, 2015 12:45
DEBUG PRINT in C as a macro
// From the TRE package
#ifdef TRE_DEBUG
#include <stdio.h>
#define DPRINT(msg) do {printf msg; fflush(stdout);} while(/*CONSTCOND*/(void)0,0)
#else /* !TRE_DEBUG */
#define DPRINT(msg) do { } while(/*CONSTCOND*/(void)0,0)
#endif /* !TRE_DEBUG */
// Updated for my use
@tomaslibal
tomaslibal / tangent_in_3d.m
Created November 5, 2015 22:49
Tangent plane to f(x, y) in GNU Octave
#{
f = x^2 + yx^3 + 2y
tangent plane at (-1, 2, f(x, y)) is:
4x - 6y - z + 19
#}
tx = ty = linspace(-5, 5, 100);
[xx, yy] = meshgrid(tx, ty);
@tomaslibal
tomaslibal / primality.js
Last active December 11, 2015 00:09
Trial division method to find whether a number is prime or composite.
/* Primality Test
* Checks if a given number is prime
* As inspired by http://www.khanacademy.org/cs/level-1-primality-test/1018672065
*/
function leastfactor(n) {
var m, i;
if (n == 0) return 0;
if (n % 1 || n*n < 2) return 1;
if (n %2 == 0) return 2;
[object HTMLElement]
[object HTMLElement]
[object HTMLElement]
[object HTMLAppletElement]
[object HTMLAreaElement]
[object HTMLElement]
[object HTMLBaseElement]
[object HTMLBaseFontElement]
[object HTMLElement]
[object HTMLElement]
@tomaslibal
tomaslibal / timers.js
Last active December 30, 2015 20:29
Simple timing of the loading events on a HTML document using JavaScript.
/**
* As the simple HTML document is loading, the script measures the time it
* takes to reach the given 'readyStates' of the DOM and of the whole
* document.
*
* document.readyState documentation:
* - http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#current-document-readiness
* - https://developer.mozilla.org/en-US/docs/Web/API/document.readyState
*
* window events documentation:
@tomaslibal
tomaslibal / bsearch.cpp
Last active January 19, 2017 15:27
A binary search like function in processing. There are no pointers by default in processing so this function works with array indexes. This example works with an array of ordered strings.
#include <cstring>
#include <cmath>
bool bsearch(const char* array, char ch)
{
int a = 0; // start of the search array
int b = strlen(array); // end of the search array
int m = 0; // the middle value
int prev; // remembers the previous middle value
while(true) {

Keybase proof

I hereby claim:

  • I am tomaslibal on github.
  • I am goodtay (https://keybase.io/goodtay) on keybase.
  • I have a public key ASBJWZ3JUY2lSiuU-aSRbTZ8rojCvX6miQ-hOsMESrBFQwo

To claim this, I am signing this object:

@tomaslibal
tomaslibal / command-line.md
Last active June 19, 2018 08:13
Collection of commands for CLI (mostly Bash), and settings of my environment (.dot files in my home directory).

Command Line snippets, info and settings

IO redirection

There are three file descriptors open by default:

  • 0 for stdin
  • 1 for stdout
  • 2 for stderr