Skip to content

Instantly share code, notes, and snippets.

View romanr's full-sized avatar
😶

Roman romanr

😶
View GitHub Profile
#!/bin/bash
# http://archives.postgresql.org/pgsql-admin/2010-05/msg00285.php
# Output lines suitable for sysctl configuration based
# on total amount of RAM on the system. The output
# will allow up to 50% of physical memory to be allocated
# into shared memory.
# On Linux, you can use it as follows (as root):
#
# ./shmsetup >> /etc/sysctl.conf
import org.apache.commons.lang.StringUtils;
private String computeMD5(String string) throws NoSuchAlgorithmException {
byte[] stringBytes = string.getBytes();
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(stringBytes, 0, stringBytes.length);
String md5 = new BigInteger(1, messageDigest.digest()).toString(16);
md5 = StringUtils.leftPad(md5, 32, '0');
@romanr
romanr / UITableViewCell.m
Created June 27, 2012 10:07 — forked from pier-oliviert/UITableViewCell.m
UITableViewCell subclass to handle indentationLevel
- (void)layoutSubviews {
[super layoutSubviews];
float indentPoints = self.indentationLevel * self.indentationWidth;
if (indentPoints > 0) {
[self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *view = (UIView *)obj;
CGFloat width = CGRectGetWidth(view.frame);
if (width > indentPoints * 2)
width -= indentPoints;
CGFloat x = CGRectGetMinX(view.frame);
@romanr
romanr / gist:3171701
Created July 24, 2012 18:32
Simulate slow network on OSX
Configure a pipe that has the appropriate bandwidth limit and delay.
sudo ipfw pipe 1 config bw 16Kbit/s delay 350ms
Attach it to all traffic going to or from port 80.
sudo ipfw add 1 pipe 1 src-port 80
sudo ipfw add 2 pipe 1 dst-port 80
Now traffic coming from or going to port 80 anywhere is limited by the pipe that you specified. Do your testing and once you get frustrated with slow access to the web remove the rules like so:
sudo ipfw delete 1
@romanr
romanr / mpnml
Created July 27, 2012 16:20 — forked from holms/mpnml
Mysql, Php-fpm, Nginx on OSX Mountain Lion
sudo port -v install mysql5-server
sudo -u _mysql mysql_install_db5
# if above command produce this error: ERROR: 1004 Can't create file '/var/tmp/#sqle967_1_0.frm' (errno: 9)
# do this:
# sudo chown -R mysql:mysql /opt/local/var/db/mysql5
# sudo chmod u+rwx,go= /opt/local/var/db/mysql5
# sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
@romanr
romanr / gist:3192047
Created July 28, 2012 06:11
Warning: Your developer_dir setting in macports.conf points to a non-existing directory. Since this is known to cause problems, please correct the setting or comment it and let macports auto-discover the correct path.
Warning: Your developer_dir setting in macports.conf points to a non-existing directory. Since this is known to cause problems, please correct the setting or comment it and let macports auto-discover the correct path.
xcode-select --print-path
sudo nano /opt/local/etc/macports/macports.conf
@romanr
romanr / gist:3283389
Created August 7, 2012 08:45
Google analytics macros
// Google Analytics Macro
#define GA_INIT_TRACKER(ACCOUNT, PERIOD, DELEGATE) \
[[GANTracker sharedTracker] startTrackerWithAccountID:ACCOUNT \
dispatchPeriod:PERIOD \
delegate:DELEGATE];
#define GA_STOP_TRACKER \
[[GANTracker sharedTracker] stopTracker];
#define GA_TRACK_PAGE(PAGE) {\
@romanr
romanr / gist:3899504
Created October 16, 2012 14:12
Setup RestKit Stack 0.20
//Create store and moc:
NSURL *baseURL = [NSURL URLWithString:myUrl];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
//not sure what this does but it's in example project
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
NSString *modelPath = nil;
#define setFrameX(_a_, _x_) { CGRect tempframe = _a_.frame; tempframe.origin.x = _x_; _a_.frame = tempframe; }
#define setFrameY(_a_, _y_) { CGRect tempframe = _a_.frame; tempframe.origin.y = _y_; _a_.frame = tempframe; }
#define setFrameWidth(_a_, _w_) { CGRect tempframe = _a_.frame; tempframe.size.width = _w_; _a_.frame = tempframe; }
#define setFrameHeight(_a_, _h_) { CGRect tempframe = _a_.frame; tempframe.size.height = _h_; _a_.frame = tempframe; }
#define printDimensions(__X__) TVLog(@"%s : Origin:(%f, %f) Size:(%f, %f)", #__X__, __X__.frame.origin.x, __X__.frame.origin.y, __X__.frame.size.width, __X__.frame.size.height)
#define printSize(a) TVLog(@"%s : (%f, %f)", #a, a.width, a.height)
#define radiansForOrientation(_a_) (_a_ == UIInterfaceOrientationPortrait? 0 : _a_ == UIInterfaceOrientationLandscapeLeft? M_PI/2.f : _a_ == UIInterfaceOrientationLandscapeRight? -M_PI/2.f : _a_ == UIInterfaceOrientationPortraitUpsideDown? -M_PI : 0)
1033edge.com
11mail.com
123.com
123box.net
123india.com
123mail.cl
123qwe.co.uk
150ml.com
15meg4free.com
163.com