Skip to content

Instantly share code, notes, and snippets.

@maddiesch
maddiesch / .bash
Created April 6, 2012 23:28
SSH into minecraft server and create a screen or connect to a screen.
alias minecraft='ssh -t username@domain.com "screen -dR"'
@maddiesch
maddiesch / NSString.m
Last active October 12, 2015 19:58
URL encode a string
- (NSString *)urlEncodeStringUsingEncoding:(NSStringEncoding)encoding {
return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding));
}
@maddiesch
maddiesch / gist:4727403
Last active November 12, 2022 15:25
Create an animated UIImage from .gif data.
+ (UIImage *)imageFromGifData:(NSData *)data {
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFTypeRef)data, NULL);
if (!source) {
return nil;
}
CFDictionaryRef dict = CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSDictionary *metadata = (__bridge NSDictionary *)dict;
CGFloat offset = 0.0;
if (metadata[@"{GIF}"]) {
NSDictionary *meta = metadata[@"{GIF}"];
@maddiesch
maddiesch / start.sh
Created July 10, 2013 03:43
A simple bash script for starting a minecraft server. Allows passing a couple command line arguments for memory and game type.
#!/bin/bash
###
## A simple bash script for starting a minecraft server
##
## Options:
## -g : Sets the game mode. 0|1 (default 0)
## -m : Sets the amount of memory to start with. (default 756)
## -t : Sets the memory type. (default M)
##
@maddiesch
maddiesch / auto.sh
Created October 15, 2013 22:09
Auto increment build numbers
echo "Bumping build number..."
plist=${PROJECT_DIR}/${INFOPLIST_FILE}
# increment the build number (ie 115 to 116)
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "No build number in $plist"
exit 2
fi
@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);
}
@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
@interface View : UIView
@property (nonatomic, weak) UIView *mySubview;
@end
@implementation View
- (UIView *)mySubview {
if (!_mySubview) {
@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
@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