Skip to content

Instantly share code, notes, and snippets.

static CGPathRef createClosedPathWithPoints(const CGPoint *points, size_t count) {
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddLines(path, NULL, points, count);
CGPathCloseSubpath(path);
return path;
}
static CGRect integralFrameForPath(CGPathRef path) {
CGRect frame = CGPathGetBoundingBox(path);
return CGRectIntegral(frame);
@voluntas
voluntas / shiguredo.rst
Last active May 22, 2024 14:27
時雨堂コトハジメ
@gfx
gfx / swfit-methods.md
Last active July 17, 2017 03:04
swiftでメソッドシグネチャどう書く問題

ドキュメントを書くとき、ObjCの setTile:forState: を Swfitでどう書くか。

setTitle(_: String!, forState: UIControlState)

フルパターン。

メリット:

  • 情報量が多くてわかりやすい
  • オーバーロードしていても曖昧でない
@chriseidhof
chriseidhof / swift.tex
Created October 8, 2014 13:44
Listings Swift config
\lstdefinelanguage{swift}
{
morekeywords={
func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return,
typealias,struct,class,enum,protocol,var,func,let,get,set,willSet,didSet,inout,init,deinit,extension,
subscript,prefix,operator,infix,postfix,precedence,associativity,left,right,none,convenience,dynamic,
final,lazy,mutating,nonmutating,optional,override,required,static,unowned,safe,weak,internal,
private,public,is,as,self,unsafe,dynamicType,true,false,nil,Type,Protocol,
},
morecomment=[l]{//}, % l is for line comment
@cocopon
cocopon / GifRecorder.pde
Last active June 9, 2019 01:07
A class that makes it easy to record a sketch in animated GIF
/*
* GifRecorder - makes it easy to record a sketch in animated GIF
* (c) 2014 cocopon.
*/
import gifAnimation.*;
/*
* Usage:
*
* 0. Install a required library before using GifRecorder.
@cromandini
cromandini / universal-framework.sh
Last active February 12, 2024 12:13 — forked from cconway25/gist:7ff167c6f98da33c5352
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures).
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
@SheffieldKevin
SheffieldKevin / compareimages.swift
Last active February 26, 2023 18:33
A couple of swift functions for comparing two CGImage using CIImage in OS X
/**
@brief Returns true if images have same meta. Width, Height, bit depth.
@discussion Assumes images are non null.
*/
func doImagesHaveSameMeta(#image1:CGImage, #image2:CGImage) -> Bool {
if CGImageGetWidth(image1) != CGImageGetWidth(image2) {
return false
}
if CGImageGetHeight(image1) != CGImageGetHeight(image2) {
@cristianca
cristianca / Create color with gradient
Last active April 14, 2023 18:25
Create a gradient UIColor from an array of colors.
func colorWithGradient(frame: CGRect, colors: [UIColor]) -> UIColor {
// create the background layer that will hold the gradient
let backgroundGradientLayer = CAGradientLayer()
backgroundGradientLayer.frame = frame
// we create an array of CG colors from out UIColor array
let cgColors = colors.map({$0.CGColor})
backgroundGradientLayer.colors = cgColors
@ykst
ykst / gist:c1b38bbea93df28da3ed
Created January 28, 2015 14:05
iOSでもOpenCLを使えるか調べてみた

iOSでもOpenCLを使えるか調べてみた

いつまで経ってもPrivate Frameworksに引き蘢っているiOSのOpenCL APIは果たして本当に使えるのか? というわけでアプリから引き摺り出してみます。Jailbreakはしません。

とりあえずdlopen(3)してみる

Private Frameworksは基本的にSDK配下のものと同じパスでランタイムにdlopen(3)する事が出来るので、実機で開いてみます。

#import "AppDelegate.h"
@royshil
royshil / SimpleVideoStabilizer.cpp
Last active May 8, 2024 05:49
A simple video stabilizer in OpenCV, based on goodFeaturesToTrack, calcOpticalFlowPyrLK and estimateRigidTransform.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/video.hpp>
#include <iostream>
using namespace cv;
using namespace std;