Skip to content

Instantly share code, notes, and snippets.

@pablasso
pablasso / gist:1966906
Created March 3, 2012 16:35
Control iOS device torch (flash)
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]) {
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn]; // AVCaptureTorchModeOff
[device unlockForConfiguration];
}
@pablasso
pablasso / gist:1967095
Created March 3, 2012 17:41
NSUserDefaults example
// set any object
[[NSUserDefaults standardUserDefaults] setObject:@"this is some string" forKey:@"test"];
[[NSUserDefaults standardUserDefaults] synchronize];
// retrieve object
[[NSUserDefaults standardUserDefaults] objectForKey:@"test"];
@pablasso
pablasso / gist:2159752
Created March 22, 2012 17:05
Filling a UITableView
// to fill a table you need to implement the protocol UITableViewDataSource in the Header and implement this //methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
@pablasso
pablasso / gist:2212624
Created March 27, 2012 04:51
Add all files with the "@" character to subversion. AKA subversion sucks.
svn status | grep "^?" | awk '{print $2}' | xargs -I {} svn add {}@
@pablasso
pablasso / gist:2415016
Created April 18, 2012 16:59
Copy an UIView by archiving and unarchiving
NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:originalView];
UIView *viewCopy = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
@pablasso
pablasso / gist:2649434
Created May 9, 2012 22:38
Growl notify on current song played on iTunes
tell application "Growl"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to {"iTunes Playing Track"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to {"iTunes Playing Track"}
-- Register our script with growl.
@pablasso
pablasso / gist:3164957
Created July 23, 2012 17:46
users on linux
useradd -d /home/user -s /bin/bash -m user
usermod -a -G group user
@pablasso
pablasso / test.rb
Created October 24, 2012 22:32
Net::FTP and UTF-8
# encoding: UTF-8
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
require 'net/ftp'
require 'debugger'
require 'fileutils'
module Net
class FTP
def storbinary(cmd, file, blocksize, rest_offset = nil, &block) # :yield: data
@pablasso
pablasso / gsl.rb
Created November 1, 2012 18:06
GSL
require 'formula'
class Gsl < Formula
url 'http://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz'
mirror 'http://ftpmirror.gnu.org/gsl/gsl-1.14.tar.gz'
homepage 'http://www.gnu.org/software/gsl/'
md5 'd55e7b141815412a072a3f0e12442042'
option :universal
def install
@pablasso
pablasso / Macros.h
Last active October 13, 2015 07:07
I usually import this on my prefix.pch
// by Marcus Zarra
#ifdef DEBUG
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
#define DLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
#endif
#define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])