Skip to content

Instantly share code, notes, and snippets.

func timerTick () {
if let newAssetWriter = self.createAssetWriterAndInputs() {
dispatch_async(_writingQueue) {
self.newAssetWriterAndInputs = newAssetWriter;
}
}
}
On OSX Yosemite and above, in a terminal window:
1. Switch to the root user.
$ sudo su -
2. Create a Dummynet pipe that represents a slow, unreliable network:
# dnctl pipe 1 config bw 10Kbit/s delay 300 plr 0.1 noerror
@paulirish
paulirish / how-to-view-source-of-chrome-extension.md
Last active October 10, 2025 13:28
How to view-source of a Chrome extension

Option 1: Command-line download extension as zip and extract

extension_id=jifpbeccnghkjeaalbbjmodiffmgedin   # change this ID
curl -L -o "$extension_id.zip" "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc" 
unzip -d "$extension_id-source" "$extension_id.zip"

Thx to crxviewer for the magic download URL.

@marchinram
marchinram / UIImage+PixelColor.swift
Last active January 19, 2022 08:53
iOS Swift UIImage subscript extension to get pixel color
import UIKit
extension UIImage {
subscript (x: Int, y: Int) -> UIColor? {
guard x >= 0 && x < Int(size.width) && y >= 0 && y < Int(size.height),
let cgImage = cgImage,
let provider = cgImage.dataProvider,
let providerData = provider.data,
let data = CFDataGetBytePtr(providerData) else {
return nil
@pyrtsa
pyrtsa / Semigroupy.swift
Last active December 28, 2015 19:40
Semigroupy grouping magic in Swift
// What people often ask DefaultDict for, could be done with just one
// extension method for Optional.
extension Optional {
mutating func mappend(z: Wrapped, _ f: (Wrapped, Wrapped) -> Wrapped) {
self = map {x in f(x, z)} ?? z
}
}
// --- Examples ------------------------------------------------------------
@pyrtsa
pyrtsa / QuotedString.swift
Created January 23, 2015 14:50
Quoted strings in Swift
struct QuotedString : Printable {
var string: String
init(_ string: String) {
self.string = string
}
var description: String {
let backslash: UnicodeScalar = "\\"
let quote: UnicodeScalar = "\""
let hex: [UnicodeScalar] = ["0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f"]
@pyrtsa
pyrtsa / Color.swift
Created January 9, 2015 08:21
Fun with default arguments in Swift initialisers
import UIKit
struct Color {
let color: UIColor
init(r: CGFloat = 0.0,
g: CGFloat = 0.0,
b: CGFloat = 0.0,
a: CGFloat = 1.0)
{
color = UIColor(red: r, green: g, blue: b, alpha: a)
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)
}
init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern
#
# Set the build number to the current git commit count.
# If we're using the Dev scheme, then we'll suffix the build
# number with the current branch name, to make collisions
# far less likely across feature branches.
# Based on: http://w3facility.info/question/how-do-i-force-xcode-to-rebuild-the-info-plist-file-in-my-project-every-time-i-build-the-project/
#
git=`sh /etc/profile; which git`
appBuild=`"$git" rev-list --all |wc -l`
if [ $CONFIGURATION = "Debug" ]; then
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"More" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
[self.tableView setEditing:NO];
}];
moreAction.backgroundColor = [UIColor lightGrayColor];
UITableViewRowAction *blurAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Blur" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];