Skip to content

Instantly share code, notes, and snippets.

@zhanghai
zhanghai / PKGBUILD
Created August 29, 2021 10:30
ibus 1.5.25-2 PKGBUILD with candidate panel position fix
# Maintainer: Felix Yan <felixonmars@archlinux.org>
pkgbase=ibus
pkgname=(ibus libibus)
pkgver=1.5.25
pkgrel=2
pkgdesc="Next Generation Input Bus for Linux"
arch=('x86_64')
url="https://github.com/ibus/ibus/wiki"
license=('LGPL')
#!/bin/bash
config_directory="$(dirname "$(realpath "$0")")"
port=2222
while [[ "$#" -gt 0 ]]; do
case "$1" in
-c|--config-directory)
config_directory="$2"
shift
@zhanghai
zhanghai / ParcelableArgs.kt
Last active April 12, 2020 23:23
ParcelableArgs and ParcelableState
/*
* Copyright (c) 2020 Hai Zhang <dreaming.in.code.zh@gmail.com>
* All Rights Reserved.
*/
package com.example.yourapplication
import android.app.Activity
import android.content.Intent
import android.os.Bundle
@zhanghai
zhanghai / LayerDrawableCompat.java
Created February 6, 2020 05:19
LayerDrawableCompat from Android 10 platform version
/*
* Copyright (C) 2006 The Android Open Source Project
*
* 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 / NaturalOrderComparator.java
Created June 16, 2018 09:57
Java Comparator for Natural Sort Order
/*
* Copyright (c) 2018 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
*
* 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 / collada-triangles.patch
Created February 19, 2018 10:19
Patch proj2_meshedit COLLADA parser to support parsing <triangles>
From ab1517d7e99a7dbe83bc1af335a23060e9ed4015 Mon Sep 17 00:00:00 2001
From: Zhang Hai <dreaming.in.code.zh@gmail.com>
Date: Sun, 18 Feb 2018 22:18:45 -0800
Subject: [PATCH] Support parsing COLLADA <triangles>.
---
src/collada.cpp | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/src/collada.cpp b/src/collada.cpp
@zhanghai
zhanghai / index.md
Last active February 8, 2018 08:59
CS 184 Mesh Editor
<style> body { padding: 100px; width: 1000px; margin: auto; text-align: left; font-weight: 300; font-family: 'Open Sans', sans-serif;
@zhanghai
zhanghai / 0-zju-network-configuration.md
Last active November 24, 2019 10:34
浙江大学 VPN 及 ZJUWLAN 网络配置
  1. 检查是否已有 ~/bin 目录(~ 即是家目录)。如果没有:   0. 创建目录:mkdir ~/bin。   1. 编辑 ~/.bashrc,加入 export PATH="$HOME/bin:$PATH"。   2. 退出终端并重新打开以使新的 ~/.bashrc 生效(或者执行 source ~/.bashrc)。

ZJUVPN

  1. 下载 https://github.com/DreaminginCodeZH/zju-net-utils/raw/master/src/zjuvpn.sh~/bin/zjuvpn(不带扩展名,用起来方便),并使用 chmod +x ~/bin/zjuvpn 添加可执行权限。
  2. 安装 xl2tpd:sudo pacman -S xl2tpd
  3. 配置 ppp
@zhanghai
zhanghai / ImageTypeFileProvider.java
Created June 18, 2017 07:41
FileProvider that can return popular types of image by parsing its header, which fixes image sharing with Google apps or Wechat moments from Glide cache
package com.yourapplication;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import com.bumptech.glide.load.ImageHeaderParser;
import com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser;
@zhanghai
zhanghai / optical-system.gjs
Last active September 7, 2023 01:18
A Gjs application for computation in an optical system comprising multiple spherical refracting surfaces
#!/usr/bin/gjs
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
function compute(surfaces, objectDistance, maxObjectAngle, objectHeight) {
const k = surfaces.length;
const r = surfaces.map(function (surface) { return surface.radius });
const n = [surfaces[0].reflectionOrDistanceLeft].concat(surfaces.map(function (surface) { return surface.reflectionRight }));