Skip to content

Instantly share code, notes, and snippets.

@zhangao0086
zhangao0086 / swift_hex.swift
Last active July 28, 2021 22:22
Convert image to hex. NSImage to byte array
// swift
var image = xxx
var rect = NSRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
let cgImage = image.CGImageForProposedRect(&rect, context: nil, hints: nil)!.takeUnretainedValue()
let bitmapRep = NSBitmapImageRep(CGImage: cgImage)
if let imageData = bitmapRep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:]) {
let len = imageData.length
var bytes = [UInt8](count: len, repeatedValue: 0)
@zhangao0086
zhangao0086 / objc_hex.m
Last active August 29, 2015 14:26
Convert image to hex
// Objective-C
UIImage *image = [UIImage imageNamed:<#(NSString *)#>];
NSData *imageData = UIImagePNGRepresentation(image);
NSInteger len = imageData.length;
Byte *bytes = (Byte *)[imageData bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:len * 5];
[result appendString:@"{"];
for (NSUInteger i = 0; i < len; i++) {
if (i) {
[result appendString:@","];
@touilleMan
touilleMan / SimpleHTTPServerWithUpload.py
Last active May 4, 2024 01:08 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload - Python3 version
#!/usr/bin/env python3
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
see: https://gist.github.com/UniIsland/3346170
"""
@kristopherjohnson
kristopherjohnson / dispatch_once.swift
Created August 12, 2014 16:25
Example of using dispatch_once() in Swift
import Foundation
var token: dispatch_once_t = 0
func test() {
dispatch_once(&token) {
println("This is printed only on the first call to test()")
}
println("This is printed for each call to test()")
}
301 https://github.com/zxdrive/imouto.host
@benbalter
benbalter / gist.md
Last active April 21, 2024 15:50
Example of how to embed a Gist on GitHub Pages using Jekyll.

Here's an example of how to embed a Gist on GitHub Pages:

{% gist 5555251 %}

All you need to do is copy and paste the Gist's ID from the URL (here 5555251), and add it to a gist tag surrounded by {% and %}.

@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 17, 2024 02:53
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application: