Skip to content

Instantly share code, notes, and snippets.

@huacnlee
huacnlee / grape_runtime_log.rb
Last active July 3, 2016 09:56
Output request time spend and parameters in log for Grape
require 'grape'
class API < Grape::API
before do
@log_start_t = Time.now
Rails.logger.info " Parameters: #{params.to_hash.except("route_info")}"
end
after do
@log_end_t = Time.now
@plentz
plentz / nginx.conf
Last active August 14, 2025 00:51
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@steveriggins
steveriggins / gist:6652508
Last active December 23, 2015 14:59
iOS 7 has a bug (or made a design decision which goes against the documentation) to set the cookie policy of NSURLConnections to whatever the user has set their cookie preferences to via Settings -> Safari. This simple method resets the cookie policy to accept always. Apple documentation for cookieAcceptPolicy: https://developer.apple.com/librar…
- (void)takeControlOfTheCookies
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self takeControlOfTheCookies];
@omz
omz / iTC Downloader.py
Created July 29, 2013 23:35
iTC Downloader
# -*- coding: utf-8 -*-
# iTC Sales Report Downloader
# When you run this for the first time, you'll need to enter your
# iTunes Connect login and vendor ID. You can find the vendor ID
# on the iTunes Connect website by navigating to "Sales and Trends";
# it's the number next to your name (top-left).
CURRENCY = 'EUR'
RESET_LOGIN = False # Set to True to remove login from keychain
@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 {} \;
@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
{
@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;
@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
}
@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];
@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