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
SELECT deviceTable.ID, ed.measure_time, ed.value
FROM (
SELECT (CASE WHEN d2.id IS NULL THEN d1.id ELSE d2.id END) AS ID
FROM device d1
LEFT JOIN device d2 ON d2.owner=d1.id
WHERE d1.parent=11 AND d1.owner IS NULL AND d1.is_active=1 AND d1.is_excluded=0 ) AS deviceTable
JOIN electricity_data ed ON ed.device_id = deviceTable.ID
Where ed.measure_time BETWEEN '2013-05-18 00:00:00' AND '2013-05-20 23:59:59'
http://www.oschina.net/translate/integrating-ext-js-with-3rd-party-libraries?print
http://stackoverflow.com/questions/16514883/expand-collapse-a-div-element
http://jsfiddle.net/Xotic750/FLUKR/
http://www.showframework.com/2012/06/extjs-4-getting-started/
http://docs.sencha.com/extjs/4.2.1/#!/guide/mvc_pt3
@fengdragon
fengdragon / pycamera.py
Last active December 22, 2015 10:39
Get Pic and update
#!/user/bin/python
#-*-coding:utf8-*-
import os, sys, time
import pygame, pygame.camera, pygame.font
from pygame.locals import *
resolution = (640, 480)
devicePath = "/dev/video0"
IMG = './shot.jpg'
@fengdragon
fengdragon / Jiandan.py
Created August 28, 2013 04:32
jiandan-MEIZHI
#!/usr/bin/env python
#coding:utf-8
import os,time,socket
import urllib,re
urlList = ['http://jandan.net/ooxx/page-%d' % i for i in range(1, 911)]
globnum = 1
$ python appcfg.py update gaetalk/
07:13 PM Host: appengine.google.com
2013-05-20 19:13:18,426 WARNING appinfo.py:1158 The datastore_admin builtin is deprecated. You can find information on how to enable it through the Administrative Console here: http://developers.google.com/appengine/docs/adminconsole/datastoreadmin.html
07:13 PM Application: nii-chinese; version: v3
07:13 PM
Starting update of app: nii-chinese, version: v3
07:13 PM Getting current resource limits.
Email: YOUR_ADMIN_EMAIL
Password for YOUR_ADMIN_EMAIL: