Skip to content

Instantly share code, notes, and snippets.

@hugozhu
hugozhu / index.html
Created September 22, 2011 03:51
Me
Hello, World!
@hugozhu
hugozhu / ddns.go
Last active August 19, 2022 06:19
动态根据宽带public ip更新dnspod登记的域名,按照 https://gist.github.com/833369 逻辑重新用Go实现了,用更少的内存开销在Raspberry Pi上跑 替换上你的Email,密码,域名ID,记录ID等参数,就可以运行了。 会在后台一直运行,每隔30秒检查一遍IP,如果修改了就更新IP。 获得domain_id可以用curl curl -k https://dnsapi.cn/Domain.List -d "login_email=xxx&login_password=xxx" 获得record_id类似 curl -k https://dnsapi.cn/Record.List -d "login_email=xxx&login_passwo…
package main
import (
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"strings"
"time"
@hugozhu
hugozhu / push.go
Last active December 10, 2015 00:19
iOS Push Service to HTTP
package main
import (
"bytes"
"crypto/tls"
"encoding/binary"
"encoding/hex"
"encoding/json"
"io"
"log"
@hugozhu
hugozhu / workflow_demo.go
Last active December 10, 2015 01:58
Use go to implement a simple workflow
func callA() string {
time.Sleep(time.Millisecond * 300)
return "Hello A"
}
func callB() string {
time.Sleep(time.Millisecond * 100)
return "Hello B"
}
@hugozhu
hugozhu / PriorityTaskExecutor.java
Created December 23, 2012 17:28
带有优先级和超时设置的任务执行者,可以实现下列逻辑: 并行处理一堆任务,返回在指定时间内完成的任务结果 并行处理一堆任务,返回在优先级最高的(第一个)任务完成或超时之前完成的任务结果
public class PriorityTaskExecutor extends ThreadPoolExecutor {
public PriorityTaskExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
public <T> List<Future<T>> invokeAllWithPriority(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit)
throws InterruptedException {
if (tasks == null || unit == null)
@hugozhu
hugozhu / douban.php
Created January 3, 2013 05:10
Raspberry Pi上听豆瓣电台的简易方法:sudo apt-get install mpg123 php5-cli,然后执行本程序即可
#!/usr/bin/env php
<?php
function fetch_page($url, $timeout = 5) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
package main
import (
"encoding/json"
"log"
"os"
)
type Result struct {
WeatherInfo *WeatherInfo
@hugozhu
hugozhu / gist:5289546
Created April 2, 2013 02:42
Pi的cosm脚本
#!/bin/bash
LOCATION=''
API_KEY=''
FEED_ID=''
####################################################
COSM_URL=http://api.cosm.com/v2/feeds/$FEED_ID?timezone=+8
cpu_load=`cat /proc/loadavg | awk '{print $2}'`
@hugozhu
hugozhu / Main.java
Last active December 16, 2015 07:58
线程等待依赖服务初始化成功 (for android)
package com.github.hugozhu.thread_wait_for_another_s_signal;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 线程等待依赖服务初始化成功 (for android)
* User: hugozhu
@hugozhu
hugozhu / du.go
Last active December 20, 2015 10:09
A Go script to count folder size.
package main
import (
"os"
"runtime"
"log"
"time"
)
var dir string