Skip to content

Instantly share code, notes, and snippets.

@zhanghai
zhanghai / wlzju_login.sh
Last active August 29, 2015 14:01
Login script for ZJUWLAN
#!/bin/bash
USERNAME=
PASSWORD=
echo "Kicking other clients offline..."
response=$(curl 'https://net.zju.edu.cn/rad_online.php' -H 'Content-Type: application/x-www-form-urlencoded' -d "action=auto_dm&username=$USERNAME&password=$PASSWORD" -s)
if [[ "$response" != "ok" ]]; then
echo "$response"
exit 1
@zhanghai
zhanghai / myls.c
Last active January 15, 2017 11:30
A simple 'ls' program that mimics the behavior of `ls -ali`
/*
* A simple 'ls' program that mimics the behavior of `ls -ali`
* Copyright (C) 2014 Zhang Hai.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
@zhanghai
zhanghai / unzip-gbk.py
Created July 5, 2014 11:12
Python script that can unzip filename with gbk encoding correctly.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# unzip-gbk.py
import os
import sys
import zipfile
print u"正在处理压缩文件 %s" % sys.argv[1].decode('utf-8')
print
@zhanghai
zhanghai / MergeListAdapter.java
Last active August 29, 2015 14:09
A ListAdapter (and a StickyListHeaders version) that merges multiple ListAdapters.
/*
* Copyright (c) 2014 Zhang Hai
*
* 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
@zhanghai
zhanghai / dpigen.sh
Created December 11, 2014 06:27
Script for generating image assets of different DPIs for Android from SVG source file, using Inkscape.
#!/bin/bash
#
# dpigen.sh: Script for generating image assets of different DPIs for Android from SVG source file, using Inkscape.
#
# Copyright (c) 2014 Zhang Hai <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@zhanghai
zhanghai / SimpleDialogFragment.java
Created December 24, 2014 07:09
Simple DialogFragment for showing dialogs that saves/restores its instance state.
/*
* Copyright (c) 2014 Zhang Hai
*
* 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
@zhanghai
zhanghai / DragUtils.java
Last active October 23, 2017 03:21
Drag and drop for sort and delete implementation.
/*
* Copyright (c) 2014-2015 Zhang Hai
*
* 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
@zhanghai
zhanghai / OnVerticalScrollListener.java
Last active May 8, 2019 07:17
RecyclerView.OnScrollListener that reports scrolled up/down or reached top/bottom.
/*
* Copyright (c) 2015 Zhang Hai <[email protected]>
* All Rights Reserved.
*/
package com.example.android;
import android.support.v7.widget.RecyclerView;
public abstract class OnVerticalScrollListener extends RecyclerView.OnScrollListener {
@zhanghai
zhanghai / ForegroundRelativeLayout.java
Last active December 1, 2015 09:25
RelativeLayout with backward-compatible foreground support.
/*
* Copyright (c) 2015 Zhang Hai
*
* 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
@zhanghai
zhanghai / douya.md
Last active January 4, 2016 03:04
关于豆芽

豆芽

Douban, Yet Another.

另一个叫豆芽的应用。

关于名字

豆芽的名字取自“Douban, Yet Another”的缩写和中文词语“豆芽”的拼音正好相同的巧合。