Skip to content

Instantly share code, notes, and snippets.

View infusion's full-sized avatar

Robert Eisele infusion

View GitHub Profile
@infusion
infusion / rational-pow.py
Last active November 25, 2018 14:10
Calculates the rational power using newton method
# Copyright Robert Eisele https://www.xarg.org/
from fractions import Fraction
import math
# Calculates (a/b)^(c/d) if solution is rational
def pow(a, b, c, d):
xn = Fraction(int(math.pow(a, c / float(d))), int(math.pow(b, c / float(d))))
abc = Fraction(a, b)**c
@infusion
infusion / up.sh
Last active February 28, 2020 11:09
Update all OSX deps
#!/bin/sh
set -e
set -x
brew update && brew upgrade
npm -g update
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3)
@infusion
infusion / create-mediawiki.sql
Created June 20, 2016 12:26
Mediawiki MySQL Table layout
-- SQL to create the initial tables for the MediaWiki database.
-- This is read and executed by the install script; you should
-- not have to run it by itself unless doing a manual install.
-- This is a shared schema file used for both MySQL and SQLite installs.
--
-- For more documentation on the database schema, see
-- https://www.mediawiki.org/wiki/Manual:Database_layout
--
-- notes:
@infusion
infusion / git-restore-file.sh
Created May 22, 2016 22:23
Find and restore a deleted file in a Git
# Find last commit for the deleted file
git rev-list -n 1 HEAD -- $path
# Checkout the commit before the the delete happened
git checkout $commit^ -- $path
@infusion
infusion / daily-reporting.sh
Last active July 6, 2016 22:12
Some curl snippets
#!/bin/bash
echo "What have you done today?"
read msg
echo "For how long have wo worked today?"
read hours
user="Robert"
pass="secret"
@infusion
infusion / double-to-buffer.js
Last active May 18, 2016 01:44
Small snippets to hack double values in JavaScript
/**
* Copyright (c) 2016, Robert Eisele (robert@xarg.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/
// Converts a JavaScript double number to a node Buffer
var DoubleToBuffer = (function() {
var FLOAT = new Float64Array(1)
return function(x) {
@infusion
infusion / recursive-primitive.js
Last active February 2, 2020 22:10
An implementation of primitive operations like addition, multiplication and so on - recursively!
/**
* @license Recursive-Primitive.js
*
* Copyright (c) 2014, Robert Eisele (robert@xarg.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/
const add = (a, b) => b === 0 ? a : add(a + 1, b - 1);
const sub = (a, b) => b === 0 ? a : sub(a - 1, b - 1);
const mul = (a, b) => b === 1 ? a : add(mul(a, b - 1), a);
@infusion
infusion / console-shapes.coffee
Last active February 5, 2016 18:26
Draw some shapes on the console using coffee script
###
# Draw some shapes on the console
# Copyright (c) 2014, Robert Eisele (robert@xarg.org)
# Dual licensed under the MIT or GPL Version 2 licenses.
###
draw = (size, cb) ->
chars = [ ":", "O" ]
i = 0
@infusion
infusion / js-min-api.sh
Last active February 3, 2016 12:49
Closure compiler API call
#!/bin/bash
# A simple helper file for Google Closure compiler
#
# Copyright (c) 2011, Robert Eisele (robert@xarg.org)
# Dual licensed under the MIT or GPL Version 2 licenses.
# Usage: ./generate.sh input.js output.js
curl --silent -d"compilation_level=ADVANCED_OPTIMIZATIONS&output_format=text&output_info=compiled_code" --data-urlencode "js_code@$1" \
@infusion
infusion / lighttpd-image.lua
Last active December 17, 2018 08:49
Some old lighttpd lua files
-- jpeg quality
quality = "85"
-- docroot of the images
docroot = "/var/www"
-- list of all sizes used
map_sizes = "sml"
-- map of prefixes : sizes to width/height - if the size doesn't exist, an error will thrown