Skip to content

Instantly share code, notes, and snippets.

View keybase.md

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 / tangent_in_3d.m
Created Nov 5, 2015
Tangent plane to f(x, y) in GNU Octave
View tangent_in_3d.m
#{
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 / debugprint.h
Created Jul 12, 2015
DEBUG PRINT in C as a macro
View debugprint.h
// 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 / command-line.md
Last active Jun 19, 2018
Collection of commands for CLI (mostly Bash), and settings of my environment (.dot files in my home directory).
View command-line.md

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
View bit_flags.c
#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 / 1x1-gif.txt
Created Feb 6, 2014
1x1 pixels transparent gif, base64 encoded.
View 1x1-gif.txt
data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
@tomaslibal
tomaslibal / timers.js
Last active Dec 30, 2015
Simple timing of the loading events on a HTML document using JavaScript.
View timers.js
/**
* 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:
View HTML4.txt
[object HTMLElement]
[object HTMLElement]
[object HTMLElement]
[object HTMLAppletElement]
[object HTMLAreaElement]
[object HTMLElement]
[object HTMLBaseElement]
[object HTMLBaseFontElement]
[object HTMLElement]
[object HTMLElement]
@tomaslibal
tomaslibal / bsearch.cpp
Last active Jan 19, 2017
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.
View bsearch.cpp
#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) {
@tomaslibal
tomaslibal / primality.js
Last active Dec 11, 2015
Trial division method to find whether a number is prime or composite.
View primality.js
/* 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;