Skip to content

Instantly share code, notes, and snippets.

@fengdragon
fengdragon / gif.swift
Created September 22, 2016 09:32 — forked from westerlund/gif.swift
Create an animated gif in swift
func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double, callback: (data: NSData?, error: NSError?) -> ()) {
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]]
let documentsDirectory = NSTemporaryDirectory()
let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif")
if let url = url {
let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil)
CGImageDestinationSetProperties(destination, fileProperties)
@fengdragon
fengdragon / index.php
Created August 3, 2016 09:20 — forked from horsley/index.php
sms + tasker转发服务的脚本
<?php
define('APP_PATH', dirname(__FILE__));
define('DATA_FILE', APP_PATH. '/sms.htdata');
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //tasker提交
if (!isset($_POST['c'])) {
die('Invalid Request!');
} else {
$data = '';
if (file_exists(DATA_FILE)) { //读入已有数据
@fengdragon
fengdragon / FastEditDistanceCandidates.cpp
Created April 25, 2016 07:11 — forked from markpapadakis/FastEditDistanceCandidates.cpp
From input string, identify all strings within a specific edit distance from it - based on deletions only.
// Compile list of tokens based on deletions, and respecting max edit distance
// Original implementation would concatenate left/right string segments using memcpy() etc, but that didn't seem right
// The idea is, to instead partition S into 1+ segments and build hash from them, no need for memory copies etc.
// This is almost x8 times faster compared to that - but it's still in the 10s of microseconds range.
//
// ( for a 31 characters long string, with max edit distance = 2, it takes 24 microseconds, including the cost for computing the FNV rolling hash )
#include <switch.h>
#include <switch_print.h>
#include <ansifmt.h>
@fengdragon
fengdragon / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console