Skip to content

Instantly share code, notes, and snippets.

View Gurpartap's full-sized avatar
:octocat:
Working from home

Gurpartap Singh Gurpartap

:octocat:
Working from home
View GitHub Profile
@Gurpartap
Gurpartap / gist:1625722
Created January 17, 2012 08:52
Custom abtableviewcell
#import <UIKit/UIKit.h>
#import "ABTableViewCell.h"
@interface MediaTableViewCell : ABTableViewCell
@end
@implementation MediaTableViewCell
@Gurpartap
Gurpartap / gist:1625737
Created January 17, 2012 08:56
Custom UILabel in cell
UILabel *messageTextLabel = [[UILabel alloc] init];
messageTextLabel.text = @"Hello World";
CGSize maximumSize = cell.contentView.frame.size; // adjust this.
UIFont *font = [UIFont systemFontOfSize:14];
CGSize stringSize = [messageTextLabel.text sizeWithFont:font
constrainedToSize:maximumSize
lineBreakMode:messageTextLabel.lineBreakMode];
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
float rotation;
CGRect frame = CGRectMake(0, 0, 480, 320);
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
rotation = 0;
frame = CGRectMake(0, 0, 320, 480);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
rotation = M_PI/2;
}
@Gurpartap
Gurpartap / gist:2622921
Created May 6, 2012 15:28
sed function with escaped keyword and replacement
function sedeasy {
sed -i "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" $3
}
sedeasy "include /etc/nginx/conf.d/*" "include /apps/*/conf/nginx.conf" /etc/nginx/nginx.conf
> bundle install --path .bundle 7 ↵ ✹ ✭Fetching gem metadata from https://rubygems.org/........
Bundler could not find compatible versions for gem "sexp_processor":
In Gemfile:
ruote (>= 2.2.0) ruby depends on
sexp_processor (~> 3.0) ruby
ruote (>= 2.2.0) ruby depends on
sexp_processor (4.0.1)
@Gurpartap
Gurpartap / app_models_server.rb
Created July 27, 2012 22:35
ruote getting started
class Server
...
pdef_provision = Ruote.process_definition do
cursor do
provision
rewind :if => '${not_ok}'
end
end
@Gurpartap
Gurpartap / base_role.rb.sh
Created July 29, 2012 23:12
chef-client cookbook getting started
(cat <<'EOP'
name "base"
description "Base role applied to all nodes"
override_attributes(
"chef_client" => {
"server_url" => "https://api.opscode.com/organizations/ORGNAME",
"validation_client_name" => "ORGNAME-validator"
}
)
run_list(
$ (cat <<'EOP'
name "base"
description "Base role applied to all nodes"
override_attributes(
"chef_client" => {
"server_url" => "https://api.opscode.com/organizations/ORGNAME",
"validation_client_name" => "ORGNAME-validator"
}
)
run_list(
@Gurpartap
Gurpartap / slash.rb
Last active December 15, 2015 02:59
brew formula for http://slash-lang.org/
# brew install ./slash --HEAD --with-lib-dir=/... --sapi=apache2 --with-json --without-mysql
require 'formula'
class Slash < Formula
homepage 'http://slash-lang.org/'
head 'git://github.com/slash-lang/slash.git'
# Core dependencies
depends_on 'gmp'
- (void)setCallbackBlock:(void (^)(id object))callbackBlock
{
//set block as an attribute in runtime
if (callbackBlock) {
objc_setAssociatedObject(self, "dismissBlockCallback", [callbackBlock copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return;
}
void (^block)(id obj) = objc_getAssociatedObject(self, "dismissBlockCallback");