Skip to content

Instantly share code, notes, and snippets.

Avatar
🍰
the cake is a lie

Leonard Schütz KCreate

🍰
the cake is a lie
View GitHub Profile
@KCreate
KCreate / ir.js
Created Dec 20, 2018
IR Language Experiments
View ir.js
// 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
Convert an amount of bytes to a human readable file size.
View data-to-human-readable.js
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
Brainfuck interpreter written in Javascript
View brainfuck.html
<!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 Dec 29, 2016
Bubblesort algorithm written in charly.
View charly-bubblesort.ch
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 Dec 26, 2016
Simple calculator written in charly.
View interpreter.ch
class Lexer {
property tokens
property source
property pos
property buffer
func constructor() {
@tokens = []
@token = null
@source = ""
View display.js
const leftpad = require('left-pad');
const fs = require('fs');
const chars = [
[
'┌─┐',
'│ │',
'│ │',
'│ │',
'└─┘',
@KCreate
KCreate / microsoft.js
Created Jun 22, 2016
How the microsoft marketing team generates new names.
View microsoft.js
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
Exponential decay headers in scss
View header.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
Personal Ubuntu Setup Script
View setup.sh
# 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 Apr 25, 2016
xhr request wrapper
View get.js
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) {
You can’t perform that action at this time.