Skip to content

Instantly share code, notes, and snippets.

@maddiesch
maddiesch / ipsum.rb
Last active August 29, 2015 14:06
Ruby lorem ipsum generator
#!/usr/bin/ruby
## Helpers
def get_word(words)
words.sample
end
def get_sentence(words)
count = (10..16).to_a.sample
str = ""
(0..count).each do
@maddiesch
maddiesch / branch.lua
Created September 5, 2014 18:14
Create a branch mine using a ComputerCraft Mining Turtle
--[[
By: skylarsch
Usage: branch <number of tunnels (8)> <length of each tunnel (10)> <space between tunnels (2)>
Each of the arguments are optional, but if you must specify all the values before the one you want to change.
--]]
-- MARK: Helper Functions
function fwd() -- Move forward
while not turtle.forward() do
@maddiesch
maddiesch / room.lua
Created September 5, 2014 18:13
Create a room with a ComputerCraft Mining Turtle
--[[
By: skylarsch
Usage: room <length (9)> <width (9)> <height (5)>
Each of the arguments are optional, but if you must specify all the values before the one you want to change.
--]]
-- MARK: Helper Functions
function fwd() -- Move forward
while not turtle.forward() do
@maddiesch
maddiesch / time-helpers.swift
Created August 6, 2014 18:07
Simple implementation of x.hours.ago() and others.
enum FloatToDate {
case Second(Double)
case Minute(Double)
case Hour(Double)
case Day(Double)
case Week(Double)
case Month(Double)
case Year(Double)
func ago() -> NSDate {
@maddiesch
maddiesch / start.bash
Created July 21, 2014 03:31
Minecraft start file
#!/bin/bash
###
#
# : Usage
# ./start -j server.jar -m 2G
# -j ) Path to the jar file
# -m ) Amount of memory to give the Java process
#
###
@maddiesch
maddiesch / minecraft.sh
Created April 20, 2014 10:12
This is the script I run when setting up a new Minecraft server.
#!/bin/bash
# The name of the .jar file for the latest version.
MINECRAFT_LATEST="minecraft_server.1.7.9.jar"
# The URL for the lates version of the minecraft server
MINECRAFT_LATEST_LINK="https://s3.amazonaws.com/Minecraft.Download/versions/1.7.9/minecraft_server.1.7.9.jar"
# The screen name for the Minecraft Server
MINECRAFT_SCREEN_NAME="Minecraft"
# Setup some variables
@maddiesch
maddiesch / minecraft_backup.sh
Created April 3, 2014 17:30
This shell script is run daily by cron to create backups of a minecraft server.
screen -R MC -X stuff "say Performing backup $(printf '\r')"
screen -R MC -X stuff "save-off $(printf '\r')"
screen -R MC -X stuff "save-all $(printf '\r')"
sleep 3
# Backup
cd /<path to backups folder>
# Delete file older than 5 days
@interface View : UIView
@property (nonatomic, weak) UIView *mySubview;
@end
@implementation View
- (UIView *)mySubview {
if (!_mySubview) {
@maddiesch
maddiesch / DrawView.h
Created December 3, 2013 21:50
Simple drawing view based on UIPanGestureRecognizer.
#import <UIKit/UIKit.h>
@interface DrawView : UIView
@property (nonatomic) CGMutablePathRef drawingPath;
@property (nonatomic) CGPoint lastPoint;
@end
@maddiesch
maddiesch / UITableView.h
Last active December 26, 2015 04:19
Blog Post On Auto Layout
#import <objc/runtime.h>
NS_INLINE void xx_MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
Method origMethod = class_getInstanceMethod(c, origSEL);
Method overrideMethod = class_getInstanceMethod(c, overrideSEL);
if(class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, overrideMethod);
}