Skip to content

Instantly share code, notes, and snippets.

View skyblue's full-sized avatar
🎯
Focusing

Skyblue skyblue

🎯
Focusing
  • Shen Zhen, Guang Dong, China
View GitHub Profile
@skyblue
skyblue / handleError.ts
Created October 23, 2020 09:14 — forked from yuya-takeyama/handleError.ts
Handle Response Error of JSON API in TypeScript (using async/await)
import fetch, { Response } from 'node-fetch';
interface ResponseWithParsedJson extends Response {
parsedJson?: any;
}
const toResponseWithParsedJson = (
res: Response,
json: any,
): ResponseWithParsedJson => {
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \\| |-- '.
/ \\||| : |||-- \
/ _||||| -:- |||||- \
| | \\\ - --/ | |
local calls, total, this = {}, {}, {}
debug.sethook(function(event)
local i = debug.getinfo(2, "Sln")
if i.what ~= 'Lua' then return end
local func = i.name or (i.source..':'..i.linedefined)
if event == 'call' then
this[func] = os.clock()
else
local time = os.clock() - this[func]
total[func] = (total[func] or 0) + time
@skyblue
skyblue / gist:4001377
Created November 2, 2012 13:30
encode audio files
#! /usr/bin/env bash
set -e
target=$1; shift
for file; do
case $target in
mp3) sox "$file" -S -r 22k -c 1 -L "${file%.*}.mp3" ;;
caf) afconvert -d 'ima4' -f 'caff' "$file" "${file%.*}.caf" ;;
esac
@skyblue
skyblue / HttpClientTest.cpp
Created October 23, 2012 13:17
HttpClientTest
#include "HttpClientTest.h"
#include "../ExtensionsTest.h"
#include <string>
USING_NS_CC;
USING_NS_CC_EXT;
HttpClientTest::HttpClientTest()
: m_labelStatusCode(NULL)
{
@skyblue
skyblue / gist:3650537
Created September 6, 2012 03:10
node oop module
var oop = require('oop');
var EventEmitter = require('events').EventEmitter;
function KitchenTimer(properties) {
this._interval = null;
this._timeout = null;
this._minutes = null;
this._start = null;
oop.inherits(this, EventEmitter);
@skyblue
skyblue / canvas_to_imgur.js
Created June 27, 2012 16:18
jquery.paste_image_reader.js
// trigger me onclick
function share(){
try {
var img = canvas.toDataURL('image/jpeg', 0.9).split(',')[1];
} catch(e) {
var img = canvas.toDataURL().split(',')[1];
}
// open the popup in the click handler so it will not be blocked
var w = window.open();
w.document.write('Uploading...');
@skyblue
skyblue / worker.js
Created January 9, 2012 04:49
nodejs worker
var net = require('net');
var path = require('path');
var sys = require('sys');
var Worker = require('webworker/webworker').Worker;
var NUM_WORKERS = 5;
var workers = [];
var numReqs = 0;
@skyblue
skyblue / visibilitychange.js
Last active March 10, 2017 02:34
visibilitychange event
document.addEventListener('visibilitychange', function(e) {
console.log('hidden:' + document.hidden,'state:' + document.visibilityState);
}, false);