Skip to content

Instantly share code, notes, and snippets.

View KCreate's full-sized avatar
🍰
the cake is a lie

Leonard Schütz KCreate

🍰
the cake is a lie
View GitHub Profile
@KCreate
KCreate / ir.js
Created December 20, 2018 15:16
IR Language Experiments
// Source code:
//
// int a = 25
// int b = 20
// int c = 0;
//
// if (a + b > 40) {
// c = 1;
// } else {
// c = 0;
@KCreate
KCreate / data-to-human-readable.js
Created May 17, 2018 13:48
Convert an amount of bytes to a human readable file size.
const bytesInKilobyte = 1000
const bytesInMegabyte = 1000000
const bytesInGigabyte = 1000000000
const bytesInTerabyte = 1000000000000
function toHumanReadable(bytes) {
if (bytes >= bytesInTerabyte) return Math.round(bytes / bytesInTerabyte * 100) / 100 + " tb";
if (bytes >= bytesInGigabyte) return Math.round(bytes / bytesInGigabyte * 100) / 100 + " gb";
if (bytes >= bytesInMegabyte) return Math.round(bytes / bytesInMegabyte * 100) / 100 + " mb";
if (bytes >= bytesInKilobyte) return Math.round(bytes / bytesInKilobyte * 100) / 100 + " kb";
@KCreate
KCreate / brainfuck.html
Created May 18, 2017 09:20
Brainfuck interpreter written in Javascript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
body * {
margin: 10px;
padding: 0;
display: block;
@KCreate
KCreate / charly-bubblesort.ch
Created December 29, 2016 19:29
Bubblesort algorithm written in charly.
Array.methods.sort = ->{
let sorted = @copy()
let left
let right
@length().times(func(i) {
(@length() - 1).times(func(y) {
left = sorted[i]
@KCreate
KCreate / interpreter.ch
Created December 26, 2016 02:29
Simple calculator written in charly.
class Lexer {
property tokens
property source
property pos
property buffer
func constructor() {
@tokens = []
@token = null
@source = ""
const leftpad = require('left-pad');
const fs = require('fs');
const chars = [
[
'┌─┐',
'│ │',
'│ │',
'│ │',
'└─┘',
@KCreate
KCreate / microsoft.js
Created June 22, 2016 07:41
How the microsoft marketing team generates new names.
const microsoft = function(name) {
const microsoft = (Math.random() < 0.5) ? 'microsoft ' : '';
const smart = (Math.random() < 0.5) ? 'smart ' : '';
const center = (Math.random() < 0.5) ? ' center' : '';
const fullname = microsoft + smart + name + center;
return fullname.trim();
}
module.exports = microsoft;
@KCreate
KCreate / header.scss
Last active May 13, 2016 19:52
Exponential decay headers in scss
$decrease: 4;
$initial: 28;
@for $i from 1 through 6 {
> h#{$i} {
// Formula: https://www.desmos.com/calculator/dhrvkbio8f
font-size: 1px * ($initial - (2 * $decrease)) + (pow($decrease, 2) / pow(2, $i));
}
@if $i < 6 {
> h#{$i} + h#{$i+1} {
@KCreate
KCreate / setup.sh
Created May 7, 2016 22:23
Personal Ubuntu Setup Script
# Install git
sudo apt-get install git
sudo mkdir ~/github/
# Uninstall all previous copies of vim
sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-common vim-gui-common
sudo apt-get build-dep vim-gnome
sudo apt-get install python-dev libncurses5-dev
sudo rm -rf /usr/local/share/vim
sudo rm /usr/bin/vim
@KCreate
KCreate / get.js
Last active April 25, 2016 21:27
xhr request wrapper
export default function get(url, method, options, _callback) {
// Allow the options to be optional
if (typeof options == 'function') {
_callback = options;
options = {};
}
// Wrap the _callback
const callback = function(err) {