Skip to content

Instantly share code, notes, and snippets.

@brunoczim
brunoczim / sizeof.sh
Created May 23, 2017 14:48
Prints the size of a given C type in shell (requires gcc, but changes for whatever compiler you use are welcome).
#!/usr/bin/env sh
if [ $# -gt 0 ]
then
CODE="#include <stdio.h>"$'\n'"int main() { printf(\"%lu\n\", sizeof($@)); return 0; }"
echo "$CODE" | gcc -o size -x c - && ./size && rm -f size
fi
@brunoczim
brunoczim / Byte.js
Created May 29, 2017 14:36
A wrapper for byte handling in JS.
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@brunoczim
brunoczim / extends.js
Created May 30, 2017 13:49
A simple snippet for reducing code when extending prototypes .
Function.prototype.extends = function(Parent) {
this.prototype = Object.create(Parent.prototype);
this.prototype.constructor = this;
};
//Now
/*
function Rectangle(w, h) {
this.width = w;
this.height = h;
@brunoczim
brunoczim / inspect.c
Last active June 2, 2017 15:04
A very simple C program for inspecting binaries.
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@brunoczim
brunoczim / memory_test.c
Last active June 19, 2017 15:19
A small C program for testing the current memory limit.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char **argv) {
size_t chunk = 0b1 << 10;
size_t interval = 0b1 << 15;
size_t i = 0;
char *ptr = malloc(chunk * (i + 1));
while (ptr != NULL) {
/// Aims to create enumerated constants.
/// # Example
/// ```
/// pub struct Foo;
/// impl Foo {
/// enum_consts! {
/// pub const: u32 =>
/// BAR,
/// BAZ,
/// }
defmodule Paramath do
def fast_fac(n, procn, pid) do
recver = spawn_link(fn -> recv(procn, 1, pid) end)
mkfac(n, div(n, procn) + rem(n, procn), recver)
end
defp mkfac(n, intval, out) do
cond do
n > intval ->
spawn_link(fn -> calc_range(n, n - intval, 1, out) end)
mkfac(n - intval, intval, out)
<?php
function utf8_to_charcode(string $utf8, &$i = null): int {
$i = (int) $i;
if ($i >= strlen($utf8)) {
return -1;
}
$first = ord($utf8[$i]);
if ($first >> 3 === 0xf << 1) {
$code = $first & 0x7;
module Stlc where
open import Agda.Builtin.String
data Type : Set where
σ : Type
τ : Type
_⟶_ : Type → Type → Type
data Var : (a : Type) → Set where
module DependentCond where
data Bool : Set where
false : Bool
true : Bool
choose : Bool → Set → Set → Set
choose true x _ = x
choose false _ x = x