This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
extension UIViewController { | |
class func fromMainStoryboard () -> UIViewController { | |
var storyboardID = NSStringFromClass(self) | |
let dotRangeOptional = storyboardID.rangeOfString(".", options: NSStringCompareOptions.allZeros) | |
if let dotRange = dotRangeOptional { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
### BEGIN INIT INFO | |
# Provides: gitlab | |
# Required-Start: $local_fs $remote_fs $network $syslog redis-server | |
# Required-Stop: $local_fs $remote_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: GitLab git repository management | |
# Description: GitLab git repository management | |
### END INIT INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream gitlab { | |
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket; | |
} | |
server { | |
listen YOUR_SERVER_IP:80; | |
server_name gitlab.YOUR_DOMAIN.com; | |
root /home/gitlab/gitlab/public; | |
# individual nginx logs for this gitlab vhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSError *error = NULL; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"id=([0-9]+)" options:NSRegularExpressionCaseInsensitive error:&error]; | |
NSTextCheckingResult *result = [regex firstMatchInString:str options:NSMatchingReportCompletion range:NSMakeRange(0, [str length])]; | |
NSLog(@"%@", [str substringWithRange:[result rangeAtIndex:1]]); // prints 123 for "id=123" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat width = 300; | |
// returns 15 | |
[text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0] forWidth:width lineBreakMode:UILineBreakModeWordWrap].height; | |
// returns 60 | |
[text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0] constrainedToSize:CGSizeMake(width, 100) lineBreakMode:UILineBreakModeWordWrap].height |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSDate *)endOfThisMonth { | |
NSDate *endOfMonth = [NSDate date]; | |
NSCalendar *calendar = [NSCalendar currentCalendar]; | |
NSDateComponents *comp = [calendar components:(NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]]; | |
[comp setMonth:[comp month]+1]; | |
[comp setDay:1]; | |
endOfMonth = [calendar dateFromComponents:comp]; | |
return [endOfMonth dateByAddingTimeInterval:-(60*60*24)]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculates the degree value of 1 meter at given geographical latitude | |
#define EARTH_RADIUS 6371000 | |
- (double)meterToDegreeAtLatitude:(double)aLatitudeInDegrees { | |
double aLatitudeInRadians = aLatitudeInDegrees * (M_PI / 180); | |
return (1 / (cos(aLatitudeInRadians) * EARTH_RADIUS)) * (180 / M_PI); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
} | |
function proml { | |
local WHITE="\[\033[40;1;37m\]" | |
local LIGHT_GRAY="\[\033[47;1;30m\]" | |
case $TERM in | |
xterm*) | |
TITLEBAR='\[\033]0;\u@\h:\w\007\]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
# "Příšerně žluťoučký kůň úpěl ďábelské ódy".strip_diacritics => | |
# "Priserne zlutoucky kun upel dabelske ody" | |
def strip_diacritics | |
self.mb_chars.normalize(:kd).to_s.gsub(/[^\x00-\x7F]/, '') | |
end | |
# Little hacks to allow using also decimal comma (used in EU) not only decimal point | |
# "3,75".to_d => 3.75 | |
# "3,75".to_f => 3.75 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bishop -- IRC bot for channel irc://chat.freenode.net/rubyonrails.cz | |
# | |
# Source: http://gist.github.com/402123.txt | |
require 'rubygems' | |
require 'cinch' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'rack/utils' |