Skip to content

Instantly share code, notes, and snippets.

@tijme
tijme / UITextViewPlaceholder.swift
Last active May 31, 2024 11:05
The correct way to implement a placeholder in a UITextView (Swift)
//
// UITextViewPlaceholder.swift
// TextViewPlaceholder
//
// Copyright (c) 2017 Tijme Gommers <tijme@finnwea.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@JoelQ
JoelQ / README.md
Created October 15, 2015 13:50
Using Shell Scripts for a Better User Experience (source for https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts)

Server scripts

This is the source for the scripts discussed in https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts

Both scripts are in the bin/ directory of the repo that contains all the markdown documents for blog posts. Users run bin/server and everything is automatically set up for them to view a local preview of the blog. bin/server-setup is a dependency of bin/server and is never run directly by users.

Maitre-d is the name of the "blog engine" discussed in the article.

@randomsequence
randomsequence / cocoa-drawing.swift
Created July 14, 2015 15:25
Drawing images with CGContext and NSGraphicsContext in Swift
//: Playground - noun: a place where people can play
import Cocoa
let bounds = CGRectMake(0, 0, 100, 100);
func DrawImageInCGContext(#size: CGSize, #drawFunc: (context: CGContextRef) -> ()) -> NSImage {
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(
@matthewfranglen
matthewfranglen / gist:a41b7b1248e3dabd41d8
Created May 13, 2015 18:37
Remove slack-redir.net from slack links
javascript:void($('a[href][onmouseover][onmousedown]').each(function(){$(this).removeAttr('onmouseover').removeAttr('onmousedown');href=$(this).attr('href');$(this).attr('href',decodeURIComponent(href.replace('https://slack-redir.net/link?url=','')));}))

Swift Don'ts

  • Don't add code cruft. Avoid parentheses around conditions in if-statements or with the return keyword. Don't add semicolons except where syntactically demanded in statements or to separate statements on the same line.
  • Don't use ALL_CAPS; use camelCase
  • Don't fight type inference. Use enumeration prefixes, self-references, and class names (with constructors) only when necessary or to clarify coding intent.
  • Don't use var when let is appropriate, especially for properties. The compiler better optimizes let statements for items whose values will not change during their lifetime. For example, Apple writes, "It is good practice to create immutable collections in all cases where the collection does not need to change. Doing so enables the Swift compiler to optimize the performance of the collections you create."
  • Don't use classes when structs will do. Use class
@ajayjapan
ajayjapan / gist:5e7ba49e51f1ca24b76d
Created August 28, 2014 18:16
Adjust content size of collection view when flexible iOS 8 simulator size changes
@interface UICollectionViewFlowLayout (InvalidateOnBoundsChange)
@end
@implementation UICollectionViewFlowLayout (InvalidateOnBoundsChange)
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewLayoutInvalidationContext *context = [super invalidationContextForBoundsChange:newBounds];
CGRect oldBounds = self.collectionView.bounds;
CGFloat widthAdjustment = newBounds.size.width - oldBounds.size.width;
require 'Benchmark'
def balanced_delimiters?(text)
openers = []
matchers = {
')' => '(',
']' => '[',
'}' => '{'
}
text.chars.each do |char|
@jazzychad
jazzychad / SPVMainViewController.m
Created December 8, 2013 22:04
example of transferring velocity of UIPanGestureRecoginizer to a UIView spring animation.
#import "SPVMainViewController.h"
@implementation SPVMainViewController
{
UIView *_weightView;
UIPanGestureRecognizer *_recog;
}
- (void)viewDidLoad
{

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@chiragchamoli
chiragchamoli / card.css
Created May 22, 2013 13:52
Google Card UI
body {
background: #f3f3f3;
}
.card {
background: url(http://i.imgur.com/wpb9BKE.jpg) center center white;
width: 350px;
height: 303px;
box-shadow: 0 1px 2px rgba(0,0,0,0.5);
border-radius: 3px 3px;
margin: 0 auto 10px;