Skip to content

Instantly share code, notes, and snippets.

@watert
watert / tailwind-colors-v4-hex.ts
Created September 19, 2025 07:07
tailwind-colors-v4-hex
export const tailwindColorsV4Hex = {
slate: {
"50": "#f8fafc",
"100": "#f1f5f9",
"200": "#e2e8f0",
"300": "#cbd5e1",
"400": "#94a3b8",
"500": "#64748b",
"600": "#475569",
"700": "#334155",
@watert
watert / create-qrcode.js
Last active October 24, 2022 02:18
适用于小程序的通用化的 QRCode 生成器
/**
create-qrcode.js
================
基于 qr.js 进行包装, 适用于小程序的通用化的 QRCode JS 生成器
qr.js 是已经比较成熟的二维码生成相关的 JS 移植,然而其内部的渲染机制需要浏览器相关特性的支持,使得在小程序端无法直接使用。
小程序中也无法使用 SVG 直接渲染,而如果使用 DOM 结构渲染或者 Canvas 渲染的话,需要的开发和接入成本也会上升。
因此这里使用的方案是: SVG 字符串生成后,转化为 dataURL 字符串,可以直接作为小程序中的 image 标签的 src 属性直接使用。
因为是 SVG 矢量图, 因此可以渲染为任意尺寸。
### INSTALLATION 安装:
@watert
watert / object-get-set.js
Created September 30, 2019 07:36
nested object set and get // extract from lodash
/*
path access: object util get/set with path access
get(obj, path) => value of obj at path:
expect(get({ a: 0 }, 'b[1].c')).toBe(null);
expect(get({ b: [0, { c: 'CCC' }] }, 'b[1].c')).toBe('CCC');
set(obj, path, value) => new object updates object value at path
expect(set({a: 0}, 'b.c', 1)).toMatchObject({ a:0, b: {c: 1} });
expect(set({a: 0}, 'b.c', 2, (v) => v * 10).b.c).toBe(20);
@watert
watert / UITableView.swift
Last active July 21, 2017 15:10
UITableView example in iOS Playground with XCode 6 beta
// Playground - noun: a place where people can play
import UIKit
class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource
{
var tableView: UITableView!
var items: NSMutableArray!
override func viewDidLoad() {
super.viewDidLoad()
@watert
watert / gulpfile.js
Created November 18, 2015 03:05
gulp requirejs example
var gulp = require("gulp");
gulp.task("rjs",function(cb){
var rjs = require("requirejs");
var config = {
baseUrl:"../scripts",
name:"main",
// optimize: "none",
mainConfigFile:"../scripts/require-config.js",
out:"../res/bundle.js",
@watert
watert / context.coffee
Created June 13, 2012 02:10 — forked from al6x/context.coffee
Adding context for Express.js req/res cycle
# Adding context for req/res cycle for Express.js.
# With context it would be possible to write more terse code:
#
# app.use ->
# @user = {name: 'Anonymous'}
# @next()
#
# app.get '/', ->
# @res.end "Hello, #{@user.name}"
#
@watert
watert / grid.less
Created March 17, 2016 03:53
LESS grid system
.desktop(@rules){
@media (min-width: 769px) { @rules(); }
}
.pad(@rules) {
@media (max-width: 769px) { @rules(); }
}
.phone(@rules){
@media (max-width: 420px) { @rules(); }
}
.clearfix(){
@watert
watert / _.random.js
Created August 29, 2013 02:10
advanced random methods for underscore
/*
_.random.str() : "Quick"
_.random.str(3) : "Jumps Jumps Fox"
_.random.list() : [43, 65, 52, 65, 49]
_.random.list(3) : [43, 65, 49]
*/
(function(){
var methods = {
num:function(num1,num2){
num1=num1||100;
getJSON = (url,callback)->
require("http").get url,(res)->
res.on "data",(data)->
data = JSON.parse data.toString()
callback data
@watert
watert / mongoBetweenDate.coffee
Created August 19, 2013 03:19
between date for mongoose query using
mongoBetweenDate = (date1,date2=false)->
parseDateStr = (date)->
dateStr = date.replace(/-/g,"/")
d = new Date dateStr
d = false if d is "Invalid Date"
d
date1 = parseDateStr date1
where = {}
if date1