Skip to content

Instantly share code, notes, and snippets.

@yeahq
yeahq / gist:2762397
Created May 21, 2012 13:45
Uninstall Homebrew manually
//http://superuser.com/questions/203707/how-to-uninstall-homebrew-osx-package-manager
Here's how they recommend doing it:
cd `brew --prefix`
rm -rf Cellar
brew prune
rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
rm -rf ~/Library/Caches/Homebrew
This should also revert your /usr/local folder to its pre-Homebrew days. See the Homebrew installation wiki for more information.
@yeahq
yeahq / gist:2402648
Created April 17, 2012 00:55
Run Javascript in UIWebView
// From: http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview
NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function myFunction() { "
"var field = document.getElementById('field_3');"
"field.value='Calling function - OK';"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
@yeahq
yeahq / gist:2391696
Created April 15, 2012 10:10
List File
//----- LIST ALL FILES -----
NSLog(@"LISTING ALL FILES FOUND");
int Count;
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"];
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
for (Count = 0; Count < (int)[directoryContent count]; Count++)
{
@yeahq
yeahq / gist:2391693
Created April 15, 2012 10:10
Move File
[[NSFileManager defaultManager] moveItemAtPath:MySourcePath toPath:MyDestPath error:nil];
@yeahq
yeahq / gist:2391691
Created April 15, 2012 10:09
Load file
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"My Directory"];
path = [path stringByAppendingPathComponent:@"My Filename"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
//File exists
NSData *file1 = [[NSData alloc] initWithContentsOfFile:path];
if (file1)
@yeahq
yeahq / gist:2391689
Created April 15, 2012 10:09
Save NSData File
NSData *file;
file = ...
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"];
path = [path stringByAppendingPathComponent:@"SomeFileName"];
[[NSFileManager defaultManager] createFileAtPath:path
contents:FileData
attributes:nil];
@yeahq
yeahq / gist:2391685
Created April 15, 2012 10:08
Create Directory
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) //Does directory already exist?
{
if (![[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:NO
attributes:nil
error:&error])
@yeahq
yeahq / gist:2391682
Created April 15, 2012 10:08
Delete Directory
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"];
NSError *error;
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does directory exist?
{
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) //Delete it
{
NSLog(@"Delete directory error: %@", error);
@yeahq
yeahq / gist:2391678
Created April 15, 2012 10:07
Delete File
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectory"];
path = [path stringByAppendingPathComponent:@"SomeFileName"];
NSError *error;
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does file exist?
{
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) //Delete it
{
NSLog(@"Delete file error: %@", error);
@yeahq
yeahq / gist:2391674
Created April 15, 2012 10:07
Does File Exist
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectory"];
path = [path stringByAppendingPathComponent:@"SomeFileName"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{