Skip to content

Instantly share code, notes, and snippets.

package main
import (
"os"
"text/template"
)
type Person struct {
Name string
}
package main
import "fmt"
type User struct {
FirstName, LastName string
}
func (user *User) Name() string {
return fmt.Sprintf("%s %s", user.FirstName, user.LastName)
@delba
delba / customView.swift
Created November 10, 2014 20:12
Auto layout and scrollView
import UIKit
class CustomView: UIView {
let text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiu
let label = UILabel()
let string = "by " as NSString
let attributedText = NSMutableAttributedString(string: string, attributes: [
NSFontAttributeName: UIFont(name: "HelveticaNeue-Medium", size: 13)!,
NSForegroundColorAttributeName: UIColor(white: 0.2, alpha: 1)
])
attributedText.setAttributes([
@delba
delba / TitleView.swift
Last active August 29, 2015 14:08
NSLayoutConstraint Visual Format
import UIKit
class TitleView: UIView {
lazy var avatar: UIImageView = {
let view = UIImageView()
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.layer.cornerRadius = 5
view.layer.masksToBounds = true
@delba
delba / HTMLString.swift
Last active August 29, 2015 14:08
Attributed text
let HTMLString: NSString = "<p>Hello, World!</p>"
let text = NSAttributedString(data: HTMLString.dataUsingEncoding(NSUnicodeStringEncoding), options: [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType
], documentAttributes: nil, error: nil)?.string // {Some "Hello, World!\n"
label.text = text
label.font = UIFont.boldSystemFontOfSize(14)
func longPress(cell: TableViewCell, recognizer: UILongPressGestureRecognizer) {
let location = recognizer.locationInView(tableView)
let indexPath = tableView.indexPathForCell(cell)
switch recognizer.state {
case .Began:
sourceIndexPath = indexPath
// Take a snapshot of the selected row using helper method.
snapshot = customSnapshotFromView(cell)
@delba
delba / BackgroundView.swift
Last active May 7, 2016 12:46
Gradient background in Swift
//
// BackgroundView.swift
// Quiz
//
// Created by Damien D on 09/09/2014.
// Copyright (c) 2014 Damien D. All rights reserved.
//
import UIKit
import UIKit
class PlayViewController: UIViewController {
var label: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
@delba
delba / expert.rb
Created April 22, 2014 14:51
Weekly notification draft
class Expert < ActiveRecord::Base
include Notifiable
has_many :trackings do
def recent
where('created_at >= ?', proxy_association.owner.notified_at)
end
end
end