Skip to content

Instantly share code, notes, and snippets.

View sinewalker's full-sized avatar

Michael Lockhart sinewalker

View GitHub Profile
@sinewalker
sinewalker / RotateDisplay.scpt
Created July 13, 2016 04:02
Applescript to toggle screen rotation. Needs to be tweeked for your specific screen arrangement.
-- this code came from Fancyham - http://fancyham.com/tips/OS_X_toggle_display_rotation_applescript.html
-- 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
@sinewalker
sinewalker / 0_reuse_code.js
Created September 16, 2016 12:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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 / oom-saver
Last active September 23, 2017 06:04
oom-saver - cron jobs to keep essential system daemons safe from the Linux OOM killer
# keep essential system daemons safe from the OOM killer
*/1 * * * * root pgrep -f "/sbin/sshd" | while read PID; do echo -17 > /proc/$PID/oom_adj; done
*/1 * * * * root pgrep -f "/sbin/rsyslogd" | while read PID; do echo -17 > /proc/$PID/oom_adj; done
@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
@sinewalker
sinewalker / sticks.bas
Last active May 25, 2020 21:10
Pick-up Sticks: early 8-bit graphics hack (BASIC)
5 REM This is for Amstrad CPC Locomotive BASIC
10 CLS
20 WHILE 1>0
30 GRAPHICS PEN 15*RND
40 MOVE 640*RND,400*RND
50 DRAW 640*RND,400*RND
60 WEND