Skip to content

Instantly share code, notes, and snippets.

@davyzhang
davyzhang / rate_limiter.go
Last active November 28, 2024 02:07
simple golang rate limiter
import (
"sync"
"time"
)
// Job represents a function to be executed
type Job func()
// RateLimiter manages rate limiting for function executions
type RateLimiter struct {
@davyzhang
davyzhang / jsb.assetsmanager.d.ts
Last active March 12, 2020 00:36
jsb.assetsmanager.d.ts cocos creator的 jsb.assetsmanager ts定义文件
/**
* The namespace for jsb exclusive APIs, all APIs in this namespace should never be used in Web engine.
* So please check whether the running environment is native or not before any usage.
* @namespace
* @name jsb
* @example
*
* if(cc.sys.isNative) {
* cc.log(cc.fileUtils.fullPathForFilename("test.js"));
* }
window._pjscMeta.scriptOutput = "out of l";
@davyzhang
davyzhang / color_export.js
Last active March 27, 2016 06:56
sketchapp plugin script to export document color as css rgba value
var doc = context.document;
var app = NSApplication.sharedApplication();
var appController = app.delegate();
var colors = doc.documentData().assets().primitiveColors();
// Convert MSArray into array
var mspalette = colors.array();
// Convert MSColors into hex strings
var palette = [];
@davyzhang
davyzhang / sqlite3 race
Last active May 30, 2022 14:33
sqlite3 routine
package main
import (
"database/sql"
"fmt"
"log"
"os"
_ "github.com/mattn/go-sqlite3"
)
#!/usr/bin/env python2.7
#coding=utf-8
'''
Created on Sep 14, 2011
@author: dawn
'''
import pexpect
import time
from subprocess import call
@davyzhang
davyzhang / sublime_dark.xml
Last active August 29, 2015 14:00
liteide sublime text color theme modified for golang in
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme version="1.0" name="Sublime Text 2">
<!--
By [email protected]
Improvements are welcome
Public Domain, 2014
Navigate To: /Applications/LiteIDE.app/Contents/Resources/liteeditor
Create a new file with the content.
Restatr LiteIDE
==> Installing subversion dependency: neon
==> Downloading http://www.webdav.org/neon/neon-0.29.6.tar.gz
Already downloaded: /Library/Caches/Homebrew/neon-0.29.6.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/neon-0.29.6.tar.gz
==> ./configure --disable-debug --prefix=/usr/local/Cellar/neon/0.29.6 --enable-shared --disable-static --with-ssl
./configure --disable-debug --prefix=/usr/local/Cellar/neon/0.29.6 --enable-shared --disable-static --with-ssl
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
@davyzhang
davyzhang / fmtcache.go
Created March 5, 2013 11:17
Use cache to reduce the call of fmt.Sprintf() to speed up the formating time to string operation
/*
Use cache to reduce the call of fmt.Sprintf() to speed up the formating time to string operation
*/
package timeutil
import (
"fmt"
"time"
)