Skip to content

Instantly share code, notes, and snippets.

View sinewalker's full-sized avatar

Michael Lockhart sinewalker

View GitHub Profile
@sinewalker
sinewalker / MaxMemory.java
Created January 21, 2017 11:18
Java MaxMemory
// See my answer to Stack Overflow: Maximum java heap size of a 32-bit JVM on a 64-bit host
// http://stackoverflow.com/questions/1434779/maximum-java-heap-size-of-a-32-bit-jvm-on-a-64-bit-os/7019624#7019624
// and my blog: http://milosophical.me/blog/2007/03/04/32-bit-windows-and-jvm-virtual-memory-limit.html
public class MaxMemory {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
long totalMem = rt.totalMemory();
long maxMem = rt.maxMemory();
long freeMem = rt.freeMemory();
@sinewalker
sinewalker / mandelbrot.sql
Created January 21, 2017 11:21
Plot the Mandelbrot set in SQL
-- I have no idea where this came from :( A work colleage showed me it.
WITH RECURSIVE
x(i)
AS (
VALUES(0)
UNION ALL
SELECT i + 1 FROM x WHERE i < 101
),
Z(Ix, Iy, Cx, Cy, X, Y, I)
@sinewalker
sinewalker / pi.py
Created January 21, 2017 11:24
Calculate π (pi) to an arbitrary deptth
# Author: Muhammad Ahmad Tirmazi
# Date: January 4, 2014
from decimal import *
import math
class PiCalculator(): #Calculates Pi
def __init__(self, prec):
getcontext().prec = prec # the precision
return
@sinewalker
sinewalker / pidigits.py
Created January 21, 2017 11:26
another Python π calculator
"""
Calculate digits of pi. This module can be run interactively with
python pidigits.py
"""
__docformat__ = 'plaintext'
import sys
import math
@sinewalker
sinewalker / randomInsult.js
Created January 21, 2017 11:31
insult generator (Javascript toy problem)
/* insult generator */
var BodyParts = ["face", "nose", "hair"];
var Adjectives = ["smelly","boring","stupid","elderberry"];
var Words = ["fly", "marmot", "stick", "monkey", "rat", "smeg"];
var pickRandom = function(pickings) {
return pickings[Math.floor(Math.random() * pickings.length)];
};
@sinewalker
sinewalker / rotate-display.scpt
Created January 21, 2017 11:32
Rotate display (landscape/portrait) on macOS
-- Now works with Mountain Lion 10.8
-- Rotate Display on machines
-- This code is offered without any liability implied or explicit.
-- Use it at your own risk.
-- Copyright 2005, 2006 Conrad Albrecht-Buehler
-- Modifications for portrait/landscape only May 2006 Bryan Wu to support toggling between only two modes - landscape and portrait
-- NOTE: UI Scripting must be enabled for this to work! Confirm that
-- "Enable access for assistive devices" is checked in the
import pygame, random
pygame.init();
scr=pygame.display.set_mode([640,400])
df=pygame.display.flip; rnd=random.randrange; draw=pygame.draw
scr.fill([0,0,255]); df()
while True:
draw.aaline(scr, [rnd(255),rnd(255),rnd(255)],
[rnd(640),rnd(400)],
[rnd(640),rnd(400)]); df()
@sinewalker
sinewalker / makeQR.py
Last active February 7, 2017 12:46
make a QR code from any text (requires qrcode: pip install qrcode pillow)
#!/usr/bin/env python
# usage: echo "My QR Text"|makeQR.py > myqr.png
# see http://alecthegeek.github.io/2013/04/28/creating-qr-codes-on-python.html
import sys
import qrcode
qrcode.make("".join(sys.stdin.readlines())).save("/dev/stdout","png")
@sinewalker
sinewalker / 2017-03-12--tmux-centos.md
Last active May 20, 2017 22:10
tmux centos/scientific
@sinewalker
sinewalker / sources.sh
Last active July 2, 2017 02:19
sourcing utility functions from a library, in bash
base=$(cd -- "$(dirname -- "$0")"; pwd -P)
source $base/util/platform.sh
source $base/util/check-required-utilities.sh