Skip to content

Instantly share code, notes, and snippets.

@rsattar
rsattar / gist:1896546
Created February 24, 2012 01:28
RegexKitLite's arrayOfCaptureComponentsMatchedByRegex: written using NSRegularExpression
// I had a need to replace the use of RegexKitLite's arrayOfCaptureComponentsMatchedByRegex with
// the built-in NSRegularExpression in iOS 5+, and didn't find an existing example, so I wrote one:
- (NSArray *) arrayOfCaptureComponentsOfString:(NSString *)data matchedByRegex:(NSString *)regex
{
NSError *error = NULL;
NSRegularExpression *regExpression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:&error];
NSMutableArray *test = [NSMutableArray array];
@shlomizadok
shlomizadok / omniauth_callbacks_controller.rb
Created May 19, 2012 10:37
How to integrate Omniauth and API
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 31, 2024 22:29
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@Moligaloo
Moligaloo / disableReturnKey.m
Created July 26, 2012 05:43
Disable the return key of keyboard
-(void)disableReturnKey{
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
@rogercampos
rogercampos / clockwork.rb
Created September 6, 2012 21:56
Capistrano running clockwork as daemon
after "deploy:stop", "clockwork:stop"
after "deploy:start", "clockwork:start"
after "deploy:restart", "clockwork:restart"
namespace :clockwork do
desc "Stop clockwork"
task :stop, :roles => clockwork_roles, :on_error => :continue, :on_no_matching_servers => :continue do
run "if [ -d #{current_path} ] && [ -f #{pid_file} ]; then cd #{current_path} && kill -INT `cat #{pid
_file}` ; fi"
end
@don9z
don9z / gist:4044409
Created November 9, 2012 08:21
Gzip compression/decompression in iOS
// from: http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html
- (NSData *)gzipInflate
{
if ([self length] == 0) return self;
unsigned full_length = [self length];
unsigned half_length = [self length] / 2;
NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
@odrobnik
odrobnik / gist:4060573
Created November 12, 2012 17:09
Comparing URLs
NSURL *a = [NSURL URLWithString:@"http://google.com/oliver.html"];
NSURL *b = [NSURL URLWithString:@"oliver.html" relativeToURL:[NSURL URLWithString:@"http://google.com"]];
if([a isEqual:b]) {
NSLog(@"Same"); // Not run
}
if([[a absoluteURL] isEqual:[b absoluteURL]]) {
NSLog(@"Same"); // Still not run
}
@tyrone-sudeium
tyrone-sudeium / gist:4594251
Last active December 11, 2015 11:29
A horizontally paging, but vertically-flowing UICollectionViewFlowLayout. Oddly, gists don't let you enter markdown into the description, so see the comment below for a description of what it does. Make sure you set its flow direction to **vertical**, even though it'll page horizontally.
@interface HorizontallyPagingCollectionViewFlowLayout : UICollectionViewFlowLayout
@end
@implementation HorizontallyPagingCollectionViewFlowLayout
- (CGSize) collectionViewContentSize
{
CGSize superSize = [super collectionViewContentSize];
CGSize frameSize = self.collectionView.frame.size;
@braking
braking / ExplodingTabBar.m
Created May 23, 2013 11:58
A custom UITabBar with a big unique center button that animates 3 buttons out of the center from any view.
#import "CustomTabBarViewController.h"
@interface CustomTabBarViewController ()
@property (nonatomic, assign) BOOL buttonsExpanded;
@end
@implementation CustomTabBarViewController
-(void) addCenterButtonWithImage:(UIImage*)buttonImage highlightImage:(UIImage*)highlightImage
{
@fabiofl
fabiofl / gist:5873100
Created June 27, 2013 00:41
Clear Mac OS X's icon cache.
sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm {} \;