Skip to content

Instantly share code, notes, and snippets.

View madson's full-sized avatar
👨‍💻
Always coding

Madson Mac madson

👨‍💻
Always coding
View GitHub Profile
@madson
madson / thanks.c
Created October 21, 2011 14:38
Thanks to Dennis Ritchie in C
#include <stdio.h>
int main() {
int codes[] = {
84, 104, 97, 110, 107, 115, 32, 68, 101, 110, 110,
105, 115, 32, 82, 105, 116, 99, 104, 105, 101, 33
};
int len = sizeof(codes)/sizeof(int);
@madson
madson / Math.m
Created October 21, 2011 17:21
Factorial calc with objective-c
#include <Foundation/Foundation.h>
@interface Math : NSObject
+ (int)factorial:(int)n;
@end;
@implementation Math
+ (int)factorial:(int)n
{
if (n == 0)
@madson
madson / factorial.c
Created October 21, 2011 17:22
Factorial calc with C
#include <stdio.h>
int factorial(int n)
{
if (n == 0)
return 1;
return n * factorial(n-1);
}
int main() {
@madson
madson / captureView.m
Created December 7, 2011 00:48
Getting UIImage from UIView
- (UIImage *)captureView:(UIView *)view {
CGRect rect = [view bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, rect);
[view.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
@madson
madson / uncrustify.cfg
Created April 29, 2013 22:05
My uncrustify configuration file for Objective-C.
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.3 (176)
#
# Alignment
# ---------
## Alignment
@madson
madson / password.pl
Created April 29, 2013 22:05
Perl script to generate encrypted password for Mac OS X.
#!/usr/bin/perl
# Gavin Brock (http://brock-family.org/gavin/perl) - June 2007
#==============================================================================#
use strict;
use warnings;
use Foundation;
#==============================================================================#
@madson
madson / matrix.c
Created May 7, 2013 14:49
matrix.c
#import <stdio.h>
#define ANSI_COLOR_GREEN "\x1b[01;32m"
#define ANSI_COLOR_RESET "\x1b[0m"
void printb(int n) {
int i;
for (i = 0; i < n; i++) {
printf("\n");
}
@madson
madson / uncrustify.sh
Created May 27, 2013 18:50
Process uncrustify in files
#! /bin/sh
if [ -z "$1" ]; then
echo "specify the file that contains a list of files"
exit
fi
files=$(cat $1)
for item in $files ; do
@madson
madson / speedup.sh
Created March 17, 2014 22:54
Script to mount directories DerivedData and iPhoneSimulator in the RAM
#!/bin/bash
# set disk size for 512 MB
disksize=$((512*(512*4)))
# mounting DerivedData virtual disk
disknum=$(hdid -nomount ram://$disksize | tr -cd '[0-9]')
newfs_hfs -v DerivedData /dev/rdisk$disknum
diskutil mount -mountPoint ~/Library/Developer/Xcode/DerivedData /dev/disk$disknum
@madson
madson / upgrade.rb
Created June 3, 2014 22:34
Script ruby to increment version number
#!/usr/bin/env ruby
COMMANDS = ['major', 'minor', 'patch']
regex = /^([0-9]+)\.?([0-9]*)\.?([0-9]*)/
version = ARGV[0]
command = ARGV[1]
unless ARGV.size > 1 or version =~ regex