Skip to content

Instantly share code, notes, and snippets.

@jmoiron
jmoiron / valuer.go
Created October 14, 2013 18:03
Example uses of sql.Scanner and driver.Valuer
package main
import (
"bytes"
"compress/gzip"
"database/sql/driver"
"errors"
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
@mbigatti
mbigatti / UIColor+RGB.swift
Last active February 14, 2021 07:22
UIColor extension that add a whole bunch of utility functions.
//
// UIColor+RGB.swift
// Copyright (c) 2014 Massimiliano Bigatti. All rights reserved.
//
import Foundation
import UIKit
/**
UIColor extension that add a whole bunch of utility functions like:
@edwardmp
edwardmp / gist:df8517aa9f1752e73353
Created May 22, 2015 16:06
Using NSURLSession with SSL public key pinning
/*
1. Adhere to the NSURLSessionDelegate delegate
2. Initialize NSURLSession and specify self as delegate (e.g. [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue: [NSOperationQueue mainQueue]];)
3. Add the method below to your class
4. Change the certificate resource name
*/
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
@plumhead
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
@DavidNix
DavidNix / logNSNotifications.m
Last active December 30, 2022 10:58
Log all NSNotifications as they are fired
static void LogNSNotifications(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo);
void LogNSNotifications(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
@dlstadther
dlstadther / example_redshift_copy.py
Last active June 9, 2021 07:35
Using Luigi's Redshift and S3
# import luigi modules
import luigi
from luigi.contrib import redshift
from luigi import configuration, s3
# import python core modules
import os
import shutil
import datetime
@miguelsaddress
miguelsaddress / octave.md
Created January 6, 2016 20:25 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &&
@jurezove
jurezove / iOS Layout Anchors.swift
Last active April 6, 2017 17:15
Demonstrating Layout Anchors on iOS
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
var container = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
container.backgroundColor = UIColor.greenColor()
XCPlaygroundPage.currentPage.liveView = container
@NSExceptional
NSExceptional / ResponseParser.swift
Last active February 21, 2018 22:55
A simple class to automate the parsing of an NSURLSessionTask response.
//
// Copyright © 2016 Tanner Bennett. All rights reserved.
//
import Foundation
typealias ResponseParserBlock = (ResponseParser) -> Void
class ResponseParser {
@imranismail
imranismail / README.md
Last active January 5, 2017 15:37
Implementing Ruby's lonely operator using Elixir's custom infix function

Implementing Ruby's lonely operator using Elixir's custom infix function

iex> import ViewHelper
iex> user = %{name: "Imran", address: %{postcode: 33160}}
iex> user ~> :name
# "Imran"
iex> user ~> :address ~> :postcode
# 33160
iex> user ~> :address ~> :country