Skip to content

Instantly share code, notes, and snippets.

View v9n's full-sized avatar
🛫
forward email at mailwip.com

Vinh v9n

🛫
forward email at mailwip.com
View GitHub Profile
@v9n
v9n / android_get_app_home_path.java
Created October 23, 2012 17:23
Android get file path
String filepath = this.getFilesDir().getAbsolutePath() + "/" + "test.txt";
File file = new File(filepath);
boolean isExists = file.exists();
File file = this.getFileStreamPath("test.txt");
boolean isExists = file.exists();
@v9n
v9n / check_spam.rb
Created November 20, 2012 18:33
Check Spam with StopSpamForum
require 'rest_client'
users = <<-eos
627,Spoldoccuple,[email protected],91.214.17.6
628,pleltexpepems,[email protected],95.26.107.123
715,sobycvdcngds,[email protected],74.121.190.76
eos
result = Hash.new
SLEEP_TIME = 1.0 / 24.0
@v9n
v9n / funnymama.rb
Created November 25, 2012 08:59
Scrape content of funnymama
require 'rubygems'
require 'mechanize'
def read_page page
pics = page.search("article.post > .post-content > .post-img > a");
pics.each do |d|
p "#{d['href']}, #{d.children[1]['src']}"
#puts d.inspect
end
end
@v9n
v9n / gist:4323171
Created December 17, 2012 22:52
Check free space on IOS device
//@author http://stackoverflow.com/questions/5712527/how-to-detect-total-available-free-disk-space-on-the-iphone-ipad-device
- (uint64_t)freeDiskspace
{
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
@v9n
v9n / ios_resource_path.h
Created December 19, 2012 23:28
API related to Resource and Path of an iOS app
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
NSLog(@"pngs in my dir: %@", [mainBundle pathsForResourcesOfType:@".png" inDirectory:@"projects pictures"]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError * error;
NSArray * directoryContents = [[[NSArray alloc] init]autorelease];
@v9n
v9n / chage_background_uitoolbar.h
Last active December 10, 2015 18:18
Change background of UiToolbar in iOS
if ([toolbar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolbar setBackgroundImage:[UIImage imageNamed:@"toolbar-background"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
} else {
[toolbar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolbar-background"]] autorelease] atIndex:0];
}
@implementation UIBarButtonItem (StyledButton)
+ (UIBarButtonItem *)styledBackBarButtonItemWithTarget:(id)target selector:(SEL)selector;
{
UIImage *image = [UIImage imageNamed:@"button_back"];
image = [image stretchableImageWithLeftCapWidth:20.0f topCapHeight:20.0f];
NSString *title = NSLocalizedString(@"Back", nil);
UIFont *font = [UIFont boldSystemFontOfSize:12.0f];
@v9n
v9n / recursive_remove.sh
Last active December 10, 2015 18:49
Recursively remove all .svn directories
find . -name .svn -print0 | xargs -0 rm -rf
find . -name .svn -exec 'rm -rf {}\;'
@v9n
v9n / gist:4479220
Created January 7, 2013 22:44
debug authkey_issues of gitolite
gitolite trigger POST_COMPILE
Most common issue:
* key is corrupted and the process of updating authorized_keys file hung up
@v9n
v9n / vnc_via_ssh.sh
Created January 16, 2013 18:06
Connect VNC via SSH. Useful when user is at login screen
#!/bin/sh
ssh -p 24 -C -f -L 5900:localhost:5900 [email protected] \
x11vnc -safer -localhost -nopw -once -display :0 \
&& sleep 5 \
&& vncviewer localhost:0