Skip to content

Instantly share code, notes, and snippets.

View layout.swift
//
// Library.swift
// LabelLayout
//
// Created by Chris Eidhof on 09.09.18.
// Copyright © 2018 objc.io. All rights reserved.
//
import UIKit
@shaps80
shaps80 / cURL+Request.swift
Last active Oct 1, 2021
Generates a cURL command representation of a URLRequest in Swift.
View cURL+Request.swift
import Foundation
extension URLRequest {
/**
Returns a cURL command representation of this URL request.
*/
public var curlString: String {
guard let url = url else { return "" }
var baseCommand = #"curl "\#(url.absoluteString)""#
@carsonmcdonald
carsonmcdonald / swift-amzn-ami.sh
Created Jan 11, 2016
Build Swift on an Amazon Linux AMI
View swift-amzn-ami.sh
#
# Notes:
#
# I used the following AMI:
# "Amazon Linux AMI 2015.09.1 (HVM), SSD Volume Type - ami-60b6c60a"
# Running on AMI: amzn-ami-hvm-2015.09.1.x86_64-gp2 (ami-60b6c60a)
#
# You probably want to use an instance type with a large amount of memory. My first
# attempt was with a c4.2xlarge but it rant out of memory without using -j option to
# limit the parallel build.
@marcboquet
marcboquet / gist:340c240c50aed6c71a1e
Created Aug 8, 2014
Create empty Swift playground files
View gist:340c240c50aed6c71a1e
#! /usr/bin/ruby
require 'pathname'
platform = "iphonesimulator" # or "macosx"
contents_xcplayground = <<XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='1.0' sdk='#{platform}'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
@steventroughtonsmith
steventroughtonsmith / gist:6763213
Created Sep 30, 2013
Non-opaque application windows in iOS 7, with optional blur. Shows the user's wallpaper under the app, with Parallax if supported.
View gist:6763213
typedef enum _UIBackgroundStyle {
UIBackgroundStyleDefault,
UIBackgroundStyleTransparent,
UIBackgroundStyleLightBlur,
UIBackgroundStyleDarkBlur,
UIBackgroundStyleDarkTranslucent
} UIBackgroundStyle;
@interface UIApplication (UIBackgroundStyle)
-(void)_setBackgroundStyle:(UIBackgroundStyle)style;
@willurd
willurd / web-servers.md
Last active Oct 20, 2021
Big list of http static server one-liners
View web-servers.md

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@norio-nomura
norio-nomura / AppDelegate.m
Created Oct 4, 2012
How to call objc_msgSendSuper()
View AppDelegate.m
//
// AppDelegate.m
// CallSuperMethod
//
#import <objc/objc-runtime.h>
#import "AppDelegate.h"
@interface Superclass : NSObject
- (NSString*)a;
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active Oct 21, 2021
Useful PostgreSQL Queries and Commands
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@mislav
mislav / easy_way.rb
Last active May 20, 2020
RESOLVE SHORT URLS before storing. Short URLs are for microblogging; you should never actually keep them around.
View easy_way.rb
require 'net/http'
# WARNING do not use this; it works but is very limited
def resolve url
res = Net::HTTP.get_response URI(url)
if res.code == '301' then res['location']
else url.to_s
end
end
@uchida
uchida / dlclt.py
Created Aug 31, 2012
CUI Downloader of Command Line Tools for Xcode
View dlclt.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# CUI Downloader of "Command Line Tools for Xcode"
# by Akihiro Uchida, CC0 dedicated to the public domain
# see http://creativecommons.org/publicdomain/zero/1.0/
import sys, os
import urllib, urllib2, cookielib
from getpass import getpass
from HTMLParser import HTMLParser