Skip to content

Instantly share code, notes, and snippets.

View mikeplate's full-sized avatar

Mikael Plate mikeplate

View GitHub Profile
@mikeplate
mikeplate / gist:703297
Created November 17, 2010 11:40
Find all subviews and concatenate a string of all class names, iOS
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableString* nameList = [[NSMutableString alloc] init];
for (UIView *subview in [self.view subviews]) {
NSString* name = NSStringFromClass([subview class]);
if ([nameList length] > 0)
[nameList appendString:@", "];
[nameList appendString:name];
}
@mikeplate
mikeplate / gist:703307
Created November 17, 2010 11:49
Set rounded rect for all subviews and background color for buttons, iOS
#import <QuartzCore/QuartzCore.h>
- (void)viewDidLoad {
[super viewDidLoad];
for (UIView *subview in [self.view subviews]) {
subview.layer.cornerRadius = 10;
if ([subview isKindOfClass:UIButton.class])
[subview setBackgroundColor:[UIColor colorWithRed:0.33 green:0.33 blue:0.9 alpha:1.0]];
@mikeplate
mikeplate / binfile-android.java
Created November 20, 2010 12:00
Store a single binary value in a file, Java, Android
// This function reads the stored value from a file on the device
void openCount() {
try {
// Open a file and data stream
FileInputStream out = openFileInput("count.bin");
DataInputStream data = new DataInputStream(out);
// Read the binary value from the stream and store in the integer
_count = data.readInt();
@mikeplate
mikeplate / gist:709171
Created November 21, 2010 21:30
Animation sample for Android
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(2000);
set.addAnimation(animation);
@mikeplate
mikeplate / gist:733416
Created December 8, 2010 15:34
Speed test for integer to string conversion on Android
long start = SystemClock.uptimeMillis();
for (int i = 0; i < 1000; i++) {
String x = Integer.toString(i);
}
long total = SystemClock.uptimeMillis() - start;
Log.i("time", String.format("Total for toString is %d", total));
start = SystemClock.uptimeMillis();
for (int i = 0; i < 1000; i++) {
String x = String.valueOf(i);
@mikeplate
mikeplate / jquery-drag-drop-plugin-issue3.html
Created October 20, 2011 07:55
Example of issue 3 for jquery-drag-drop-plugin
<!DOCTYPE html>
<html>
<head>
<title>Issue 3</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="http://mikeplate.github.com/jquery-drag-drop-plugin/jquery.drag-drop.plugin.js"></script>
<style>
.whileDragging {
background-color: yellow;
}
@mikeplate
mikeplate / gist:1331810
Created November 1, 2011 20:29
My main AutoHotkey file with favorite shortcuts
; Set some variables we'll need later
SysGet, DeskW, 16
SysGet, DeskH, 62
SysGet, WinBorderH, 46
DeskH := DeskH - WinBorderH*8
; Create the window group EXPLORER so we can treat all such windows as a group further down
GroupAdd,EXPLORER, ahk_class CabinetWClass
#WinActivateForce
return
@mikeplate
mikeplate / setup-vsftpd.sh
Created November 15, 2011 17:12
Set up vsftpd for multiple users
#!/bin/bash
#
# This script is used to set up vsftpd for multiple virtual users with predefined passwords
# fetched from a text file. The vsftpd configuration file that is outputted enforces
# FTP Explicit TLS for all client connections.
#
# The text file with predefined users and passwords must have the following format:
# <username>:<password>
#
userfile=users.txt
@mikeplate
mikeplate / gist:1368122
Created November 15, 2011 19:54
Set up Ruby, Passenger and Nginx
#!/bin/bash
if [ "$(whoami)" != "root" ]; then
echo "Run as root!"
exit 1
fi
apt-get -y install curl git build-essential bison openssl libreadline5 libreadline-dev
apt-get -y install zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3
apt-get -y install libreadline-dev libxml2-dev autoconf libtool
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
@mikeplate
mikeplate / sp-create-users.ps1
Created September 26, 2012 19:15
Create all users required by the AutoSPInstaller script
$user_list = "SPS_INSTALL", "SQL_SERVICE", "SPS_FARM", "SPS_APP_POOL1", "SPS_MYSITE", "SPS_SERVICES", "SPS_SEARCH", "SPS_CRAWL", "SPS_PROFILE", "SPS_CACHEADM", "SPS_CACHERD"
function Gen-Password([int]$length) {
$assembly = Add-Type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword($length, 2)
}
function Get-ScriptDirectory() {
$invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $invocation.MyCommand.Path