Skip to content

Instantly share code, notes, and snippets.

View ahbou's full-sized avatar
shipping

Ahmed Bouchfaa ahbou

shipping
View GitHub Profile
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@saoudrizwan
saoudrizwan / Storage.swift
Last active October 27, 2021 01:51
Helper class to easily store and retrieve Codable structs from/to disk. https://medium.com/@sdrzn/swift-4-codable-lets-make-things-even-easier-c793b6cf29e1
import Foundation
public class Storage {
fileprivate init() { }
enum Directory {
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud.
case documents
@joaomdmoura
joaomdmoura / page_scrapper.rb
Last active December 29, 2016 20:45
Pure Old Ruby Object (PORO) HTML scraper with a simple DSL
require 'nokogiri'
require 'open-uri'
class PageScrapper
attr_accessor :url, :selector
IMG_SRC_REGEX = /src="([a-zA-Z\/0-9:.-_]+\.[a-zA-Z]{3})/
URL_REGEX = /http[s]?:\/\/[a-zA-Z0-9].+\.[a-z]{2,3}(\.[a-z]{2})?/
def initialize(url)
/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@subdigital
subdigital / minimal-vim.sh
Last active August 17, 2021 15:44
minimal vim setup for linux servers / vms + swift
#! /bin/bash
set -e
if [[ -f ~/.vimrc ]]
then
echo "You already have a ~/.vimrc. Aborting to avoid losing data..."
exit 1
fi
@natecook1000
natecook1000 / nshipster-new-years-2016.md
Last active July 10, 2018 19:24
NSHipster New Year's 2016

Greetings and salutations, NSHipsters!

As the year winds down, it's a tradition here at NSHipster to ask you, dear readers, to offer up your favorite tricks and tips from the past year as gifts to your fellow hipsters. With iOS 9, El Capitan, brand new watch- and tvOS's, and the open-sourcing of some minor Apple-related tech, there's bound to be lots to share.

Submit your favorite piece of Swift or @objc trivia, helpful hints, unexpected discoveries, useful workarounds, useless fascinations, or anything else you found cool this year. Just comment below!

If you need inspiration, try [the list from last year][2015], or [from the year before][2014], or [from the year before that][2013].

@KentarouKanno
KentarouKanno / UILocalNotification.md
Last active June 23, 2018 22:50
UILocalNotification

UILocalNotification

★ 通知の初期化(ユーザーへの許可を促す)

let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
UIApplication.shared.registerForRemoteNotifications()

★ 通知を作成

@stollcri
stollcri / ReplayKitExample.m
Last active May 9, 2018 18:11
Created a "Single View Application" project and added ReplayKit code to the ViewController files
//
// ViewController.h
// ReplayKitExample
//
// Created by Christopher Stoll on 6/11/15.
// Copyright © 2015 Christopher Stoll. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <ReplayKit/ReplayKit.h>
@m
m / gist:f27ae57113e34392c6d5
Created May 30, 2015 14:16
Auto-unsubscribe on Unroll.me
var i = 0;
function unroll_me_unsubscribe() {
// Bail if share modal (indicating free limit reached) is encountered.
if ( jQuery( '#fb-root' ).length > 0 ) { return; }
var unsub_link = jQuery( '.LetterList a.uicon-set-unsubscribe:first' );
if ( unsub_link.length > 0 ) {
document.getElementById( unsub_link.attr( 'id' ) ).click();
if ( i++ < 6000 ) { /* Upper limit in case something goes wrong. */
setTimeout( unroll_me_unsubscribe, 1500 );
}