Skip to content

Instantly share code, notes, and snippets.

View mingsai's full-sized avatar
🎯
Focusing

Tommie N. Carter, Jr. mingsai

🎯
Focusing
View GitHub Profile
@Koze
Koze / RFTDAttachment.m
Last active May 15, 2017 20:48
Retrieve image data from NSTextAttachment
UIPasteboard *pboard = [UIPasteboard generalPasteboard];
NSData *data = [pboard valueForPasteboardType:@"com.apple.flat-rtfd"];
NSAttributedString *aString = [[NSAttributedString alloc] initWithData:data
options:@{NSDocumentTypeDocumentAttribute: NSRTFDTextDocumentType}
documentAttributes:nil
error:nil];
NSRange range = NSMakeRange(0, aString.length);
NSDictionary *attributes = [aString attributesAtIndex:0 effectiveRange:&range];
NSLog(@"%@", attributes);
//
// SimpleScrollingStack.swift
// A super-simple demo of a scrolling UIStackView in iOS 9
//
// Created by Paul Hudson on 10/06/2015.
// Learn Swift at www.hackingwithswift.com
// @twostraws
//
import UIKit
@Ben-G
Ben-G / UnsafePointerPlayground.swift
Last active February 17, 2017 17:24
Playing with unsafe Pointers
//: Playground - noun: a place where people can play
import Foundation
let arr = [1,5,7,8]
let pointer = UnsafeMutablePointer<[Int]>.alloc(4)
pointer.initialize(arr)
let x = pointer.memory[3]
@MarcoMig
MarcoMig / ClassA.swift
Last active December 8, 2017 03:38
Swift: Async callback block pattern example
//ClassA it's the owner of the callback, he will trigger the callback when it's the time
class ClassA {
//The property of that will be associated to the ClassB callback
var callbackBlock : ((error : NSError?, message : String?, adress : String? ) -> Void)?
init() {
//Do Your staff
}
//Define your function with the clousure as a parameter
@venkatperi
venkatperi / CGContextExt.swift
Created April 24, 2015 20:54
CGContext Syntactic Sugar
// CGContextABCD(context!, ...) becomes context?.ABCD(...)
import Cocoa
extension CGContext {
func saveGState() { CGContextSaveGState(self) }
func restoreGState() { CGContextRestoreGState(self) }
func scaleCTM( sx: CGFloat, sy: CGFloat) { CGContextScaleCTM(self, sx, sy) }
func translateCTM( tx: CGFloat, ty: CGFloat) { CGContextTranslateCTM(self, tx, ty) }
func rotateCTM( angle: CGFloat) { CGContextRotateCTM(self, angle) }
@john-07
john-07 / gist:07f1615ec6a55bc676d2
Created April 24, 2015 07:27
Core Data helpers
func fetchAll<T:NSManagedObject>(type:T.Type, predicate:NSPredicate?, sorts:[AnyObject]?=nil)->[T]{
let entityName = NSStringFromClass(type);
let request = NSFetchRequest(entityName:entityName);
request.predicate = predicate;
request.sortDescriptors = sorts;
var error:NSError?=nil;
if let rows = context.executeFetchRequest(request, error:&error) {
return rows as [T];
}else{
DDLogError("\(error)");
@georgiana-gligor
georgiana-gligor / osx-pdf-from-markdown.markdown
Last active April 25, 2025 07:17
Markdown source for the "Create PDF files from Markdown sources in OSX" article

Create PDF files from Markdown sources in OSX

When [Markdown][markdown] appeared more than 10 years ago, it aimed to make it easier to express ideas in an easy-to-write plain text format. It offers a simple syntax that takes the writer focus away from the formatting, thus giving her time to focus on the actual content.

The market abunds of editors to be used for help with markdown. After a few attempts, I settled to Sublime and its browser preview plugin, which work great for me and have a small memory footprint to accomplish that. To pass the results around to other people, less technical, a markdown file and a bunch of images is not the best approach, so converting it to a more robust format like PDF seems like a much better choice.

[Pandoc][pandoc] is the swiss-army knife of converting documents between various formats. While being able to deal with heavy-weight formats like docx and epub, we will need it for the more lightweight markdown. To be able to generate PDF files, we need LaTeX. On OSX, the s

@lukehedger
lukehedger / ffmpeg-compress-mp4
Last active May 2, 2025 14:50
Compress mp4 using FFMPEG
$ ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4
@galiak11
galiak11 / Query.swift
Last active September 1, 2016 17:23
Swift CoreData Query API
import Foundation
import CoreData
/**
Query: this is a Swift Query API for CodeData.
Usage example:
// fetch multiple rows
let people = Query("Person").whereEqual( "lastName", lastName ).sort( "name" ).fetch()
@JadenGeller
JadenGeller / Swift Callback.swift
Last active February 12, 2016 13:37
Swift Callback Function Transformation
/*
* Takes in a function that transform T to U and
* a callback that takes arguments of type T and U
* and returns a function that performs f but calls
* the callback before returning
*/
func callback<T,U>(f: T -> U, c: (T, U) -> ()) -> T -> U{
return { x in
let r = f(x)
c(x,r)