Skip to content

Instantly share code, notes, and snippets.

View goppinath's full-sized avatar

Goppinath Thurairajah goppinath

View GitHub Profile
@frozendevil
frozendevil / gist:4116647
Created November 20, 2012 07:53
Talking to sockets through dispatch_io_read
//
// ACAppDelegate.m
// SocketTest
//
// Created by Izzy Fraimow on 11/19/12.
//
#import "ACAppDelegate.h"
#include <arpa/inet.h>
@yfujiki
yfujiki / gist:77df1725be99a3750634
Last active August 1, 2017 08:56
Simple dispatch_group and dispatch_semaphore sample
//: Playground - noun: a place where people can play
import Foundation
// DispatchGroup sample.
// we are waiting for all async blocks to be finished before typing "[Dispatch Group] sample has finished"
let group = DispatchGroup()
let q1 = DispatchQueue.global(qos: .background)
let q2 = DispatchQueue.global(qos: .background)
@hiroshi-maybe
hiroshi-maybe / dijkstra.js
Created April 18, 2014 09:12
Implementation of `Dijkstra's algorithm` in JavaScript
var graph1 = {
vertex: ["1","2","3"],
edge: [,
/* vertex1, vertex2, weight */
["1", "2", 4],
["1", "3", 7],
["2", "3", 1]
]
},
graph2 = {
@skeep
skeep / Dijkstra.js
Last active August 13, 2018 19:43
Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later. This programme is an implementation of https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm#Pseudocode
/**
* Basic Graph data structure implementation
* @constructor
*/
var Graph = function() {
this.vertices = {};
};
Graph.prototype.add = function(name, edges) {
edges = edges || null;
@artemstepanenko
artemstepanenko / NSOperationQueue+Completion.h
Created November 23, 2013 21:57
This NSOperationQueue's category solves very simple task. Now you can add completion callback to NSOperationQueue instance.
//
// NSOperationQueue+Completion.h
// QueueTest
//
// Created by Artem Stepanenko on 23.11.13.
// Copyright (c) 2013 Artem Stepanenko. All rights reserved.
//
typedef void (^NSOperationQueueCompletion) (void);
@syshen
syshen / gist:c24d127e1adc2783e0e7
Last active June 28, 2020 19:31
Universal framework
######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveImage(image: UIImage, albumName: String, completion: (PHAsset?)->()) {
if let album = self.findAlbum(albumName) {
saveImage(image, album: album, completion: completion)
return
}
@kristopherjohnson
kristopherjohnson / DispatchGroupDemo.swift
Last active May 28, 2021 14:40
Simple demo of dispatch_group_async/dispatch_group_notify/dispatch_group_wait in Swift
import Foundation
let notified = dispatch_semaphore_create(0)
let group = dispatch_group_create()
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
for n in 0..<20 {
dispatch_group_async(group, queue) {
let timeInterval = Double(arc4random_uniform(1000)) * 0.01
@matsuda
matsuda / NSData+AES.h
Created February 25, 2014 07:14
Objective-C code for encrypt and decrypt by AES-128 encryption.
/**
http://mythosil.hatenablog.com/entry/20111017/1318873155
http://blog.dealforest.net/2012/03/ios-android-per-aes-crypt-connection/
*/
@interface NSData (AES)
- (NSData *)AES128EncryptedDataWithKey:(NSString *)key;
- (NSData *)AES128DecryptedDataWithKey:(NSString *)key;
- (NSData *)AES128EncryptedDataWithKey:(NSString *)key iv:(NSString *)iv;
@werediver
werediver / WiFiSsid.swift
Created July 14, 2016 12:47
Get the connected Wi-Fi network SSID on iOS (in Swift).
import Foundation
import SystemConfiguration.CaptiveNetwork
func getWiFiSsid() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
break