Skip to content

Instantly share code, notes, and snippets.

View Ben-G's full-sized avatar
💭
💻

Benjamin Encz Ben-G

💭
💻
View GitHub Profile
@mchambers
mchambers / serializer.swift
Created June 25, 2014 07:49
A simple, limited model-to-JSON serializer in Swift.
// Here we'll use Swift's IDE-supporting reflect()
// function to build a basic JSON serializer.
// Per the fine engineers at WWDC, Swift's reflection support
// exists purely to support the IDE and the Playground. But
// we can have some fun with it anyway. ;)
class SerializerBase {
}
@dankogai
dankogai / church.swift
Created June 15, 2014 09:44
Lambda Calculus in Swift
//
// main.swift
// church
//
// Created by Dan Kogai on 6/15/14.
// Copyright (c) 2014 Dan Kogai. All rights reserved.
//
/* Operators */
@kristopherjohnson
kristopherjohnson / partial.swift
Last active March 3, 2022 16:11
Experiments with partial function application in Swift
func partial<A, B, T>(f: (A, B) -> T, a: A) -> (B) -> T {
return { f(a, $0) }
}
func bind2nd<A, B, T>(f: (A, B) -> T, b: B) -> (A) -> T {
return { f($0, b) }
}
func partial<A, B, C, T>(f: (A, B, C) -> T, a: A) -> (B, C) -> T {
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@jquave
jquave / jamesonquave.com comment reply
Created June 3, 2014 01:05
jamesonquave.com comment reply
import UIKit
class AnotherClass {
var someVar = 1
let someConst = 2
func somePrivateFunc() -> Bool {
return true
}
@armadsen
armadsen / MultipleClassExtensions.m
Last active January 4, 2016 11:59
Demonstration of multiple class extensions in Objective-C. For http://stackoverflow.com/a/21343983/344733
#import <Foundation/Foundation.h>
@interface TestClass : NSObject
@end
@interface TestClass ()
@property NSString *name;
diff --git a/protobuf-2.5.0/src/google/protobuf/stubs/once.cc b/protobuf-2.5.0/src/google/protobuf/stubs/once.cc
index 1e24b85..e9056ac 100644
--- a/protobuf-2.5.0/src/google/protobuf/stubs/once.cc
+++ b/protobuf-2.5.0/src/google/protobuf/stubs/once.cc
@@ -63,7 +63,7 @@ void SchedYield() {
} // namespace
void GoogleOnceInitImpl(ProtobufOnceType* once, Closure* closure) {
- internal::AtomicWord state = internal::Acquire_Load(once);
+ internal::AtomicWord state = internal::Acquire_Load((volatile internal::Atomic32 *)once);
@JaviSoto
JaviSoto / gist:6926083
Last active April 22, 2025 09:09
Rotation transformation with anchor point
- (void)rotateView:(UIView *)view
byRadianDegrees:(CGFloat)radianDegrees
withAnchorPoint:(CGPoint)relativeAnchorPoint
{
const CGRect viewBounds = view.bounds;
const CGPoint anchorPoint = CGPointMake(viewBounds.size.width * relativeAnchorPoint.x, viewBounds.size.height * relativeAnchorPoint.y);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, anchorPoint.x, anchorPoint.y);
transform = CGAffineTransformRotate(transform, radianDegrees);
@floriankugler
floriankugler / gist:6870499
Last active September 29, 2023 15:56
Mapping of NSURLConnection to NSURLSession delegate methods. Created by Mattt Thompson.
NSURLConnection | NSURLSession
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connectionShouldUseCredentialStorage: |
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge: | NSURLSessionDelegate URLSession:didReceiveChallenge:completionHandler:
| N
@liu7yong
liu7yong / unpack_plist.py
Last active April 3, 2019 02:00 — forked from wonkwh/unpack_plist.py
extract image from plist,png file created by texturepacker
#/usr/local/bin/python
import os,sys
from xml.etree import ElementTree
from PIL import Image
def tree_to_dict(tree):
d = {}
for index, item in enumerate(tree):
if item.tag == 'key':
if tree[index+1].tag == 'string':