Skip to content

Instantly share code, notes, and snippets.

View Lejdborg's full-sized avatar

Christoffer Lejdborg Lejdborg

View GitHub Profile
@Lejdborg
Lejdborg / uitextview-margin.m
Created September 14, 2013 19:27
How to add left and right margins to a UITextView...
float padding = 10.0;
NSMutableParagraphStyle *editorParagraphStyle = [NSMutableParagraphStyle new];
[editorParagraphStyle setHeadIndent:padding];
[editorParagraphStyle setFirstLineHeadIndent:padding];
[editorParagraphStyle setTailIndent:-padding];
NSDictionary *textAttributes = @{
NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:14],
NSParagraphStyleAttributeName: editorParagraphStyle
@Lejdborg
Lejdborg / about.md
Created November 28, 2012 10:54 — forked from pilt/about.md
Programming Achievements: How to Level Up as a Developer

Programming Achievements: How to Level Up as a Developer

  1. Select a particular experience to pursue.
  2. Pursue that experience to completion. (Achievement unlocked!)
  3. Reflect on that experience. Really soak it in. Maybe a blog post would be in order?
  4. Return to Step 1, this time selecting a new experience.

*This gist is a fork of the gist from [this blog post][1] and this [Gist][2].

@Lejdborg
Lejdborg / gist:4152775
Created November 27, 2012 06:43
- [UILabel resizeToFit:]
/**
* Resizes a UILabel to be exactly the size it needs to be to fit it's contents
* within the constraints of CGSize.
*
* @param maxSize The maximum allowable size the label may fit in
*/
- (void)resizeToFit:(CGSize)maxSize {
CGSize expectedLabelSize = [[self text] sizeWithFont:[self font]
constrainedToSize:maxSize
lineBreakMode:[self lineBreakMode]];
@Lejdborg
Lejdborg / gendoc.sh
Created May 11, 2012 07:47
Appledoc generation guide
appledoc --project-name "YOUR_PROJECT_NAME" --project-company "YOUR_COMPANY_NAME" --company-id "COMPANY_BUNDLE_IDENTIFIER" --output doc --no-create-docset .
# Ex:
# appledoc --project-name "NMSSH" --project-company "Nine Muses AB" --company-id "se.ninemuses" --output doc --no-create-docset .
@Lejdborg
Lejdborg / gist:2626688
Created May 7, 2012 08:39
Updated UIPageControl for paged UIScrollView
/**
* Set the UIScrollView's delegate to self, and set self's protocol to UIScrollViewDelegate.
*
* This works with a horizontally paged scroll view but can be easily converted to vertical,
* just switch all "width" to "height".
*/
- (void)scrollViewDidScroll:(UIScrollView *)sender {
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = _scrollView.frame.size.width;
int currentPage = ceil((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth);
@Lejdborg
Lejdborg / .htaccess
Created May 17, 2011 12:43
Rewrite www URL to non-www independent of the domain name (Apache)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) http://%{SERVER_NAME}/$1 [R=301,L]
@Lejdborg
Lejdborg / .htaccess
Created May 9, 2011 05:31
Rewrite non-www URL to www independent of the domain name (Apache)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{SERVER_NAME}/$1 [R=301,L]
@Lejdborg
Lejdborg / clean-uiwebview-scroll.m
Created April 26, 2011 09:28
Prevent ugly background and shadows when UIWebView is scrolled too far...
myWebView.backgroundColor = [UIColor clearColor];
id scrollview = [myWebView.subviews objectAtIndex:0];
for (UIView *subview in [scrollview subviews]) {
if ([subview isKindOfClass:[UIImageView class]]) subview.hidden = YES;
}
@Lejdborg
Lejdborg / get-human-time.php
Created March 31, 2011 18:40
Convert timestamp to "X hours since"
<?php
function get_human_time($timestamp) {
$since = time() - $timestamp;
$chunks = array(
array(60 * 60 * 24 * 365, 'year', 'years'),
array(60 * 60 * 24 * 30, 'month', 'months'),
array(60 * 60 * 24 * 7, 'week', 'weeks'),
array(60 * 60 * 24, 'day', 'days'),
array(60 * 60, 'hour', 'hours'),