Skip to content

Instantly share code, notes, and snippets.

@prisoner
prisoner / queue.go
Created January 10, 2019 08:03
queue with timeout
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@prisoner
prisoner / config.json
Created May 27, 2017 01:29 — forked from twalker/config.json
inline-styles using phantomjs
{
"ignoreSslErrors": true,
"localToRemoteUrlAccessEnabled": true,
"webSecurityEnabled": false
}
@prisoner
prisoner / display-indicator.py
Created March 6, 2017 02:05 — forked from philayres/display-indicator.py
Unity indicator for simple clock and date display
#!/usr/bin/env python
# Unity indicator for evolution-less clock and date display
# author: phil ayres
# 24 Oct 2011
import gobject
import gtk
import appindicator
import os, sys
import time
import redis.clients.jedis.Jedis;
import java.util.BitSet;
Jedis redis = new Jedis("localhost");
public int uniqueCount(String action, String... dates) {
BitSet all = new BitSet();
for (String date : dates) {
String key = action + ":" + date;
BitSet users = BitSet.valueOf(redis.get(key.getBytes()));
@prisoner
prisoner / redis-bitmaps-1.java
Last active December 20, 2015 19:09
Fast, easy, realtime metrics using Redis bitmaps
import redis.clients.jedis.Jedis;
import java.util.BitSet;
Jedis redis = new Jedis("localhost");
public int uniqueCount(String action, String date) {
String key = action + ":" + date;
BitSet users = BitSet.valueOf(redis.get(key.getBytes()));
return users.cardinality();
}
/*jslint undef: true, nomen: true, eqeqeq: true, plusplus: true, newcap: true, immed: true, browser: true, devel: true, passfail: false */
/*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */
var dbg = (typeof console !== 'undefined') ? function(s) {
console.log("Readability: " + s);
} : function() {};
/*
* Readability. An Arc90 Lab Experiment.
* Website: http://lab.arc90.com/experiments/readability
#compdef go
_arguments "1:commands:((\
build\:'compile packages and dependencies' \
clean\:'remove object files' \
doc\:'run godoc on package sources' \
env\:'print Go environment information' \
fix\:'run go tool fix on packages' \
fmt\:'run gofmt on package sources' \
get\:'download and install packages and dependencies' \
@prisoner
prisoner / hello.go
Created August 7, 2011 13:00
hello Go
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
@prisoner
prisoner / underscores_in_numeric_literals.java
Created July 29, 2011 08:21
Underscores in Numeric Literals
//正确
long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;
@prisoner
prisoner / try-with-resources.java
Created July 29, 2011 08:05
The try-with-resources Statement
public static void viewTable(Connection con) throws SQLException {
String query = "select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES";
try (Statement stmt = con.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");