Skip to content

Instantly share code, notes, and snippets.

View zerda's full-sized avatar

SilverFox zerda

  • Shanghai, China
View GitHub Profile
@zerda
zerda / ImmStatus.cs
Last active August 29, 2015 14:00
检测输入法的输入状态
public class MainWindow {
/// <summary>
/// 输入法的输入框被打开,已有文本在内
/// </summary>
/// <returns>若有文本正在输入则为 true,否则为 false</returns>
private bool IsImeCompositionWindowOpened() {
var helper = new WindowInteropHelper(this);
var hImc = NativeMethods.ImmGetContext(helper.Handle);
const int readType = NativeMethods.GCS_COMPSTR;
try {
@zerda
zerda / GlobalHotKey.cs
Last active August 29, 2015 14:00
如何使用全局快捷键
public class MainWindow {
private short atom;
private HwndSource hwndSource;
public MainWindow {
this.Loaded += (sender, args) => {
// 挂载全局快捷键
var helper = new WindowInteropHelper(this);
hwndSource = HwndSource.FromHwnd(helper.Handle);
if(hwndSource != null)
@zerda
zerda / GetUrlParameter.js
Last active June 30, 2016 00:00
Parse Url Param by Vanilla JavaScript
function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName
for (var i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=')
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1]
}
@zerda
zerda / bash_completion.sh
Created May 28, 2017 08:15
Bash Completion Init Script
# Check for interactive bash and that we haven't already been sourced.
if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_COMPAT_DIR-}" ]; then
# Check for recent enough version of bash.
if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
[ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
# Source completion code.
@zerda
zerda / RandomString.java
Created December 24, 2017 05:52
Create an random string in Java
import java.security.SecureRandom;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
/**
* Random String Generator.
*
* <code>new RandomString().nextString()</code>
@zerda
zerda / elasticsearch.yml
Last active October 6, 2018 10:33
Elasticsearch 4.6 minimal cluster in Kubernetes
#
# Copyright 2017-2018 The Jaeger 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 distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
@zerda
zerda / backup-job.yml
Last active October 6, 2018 23:57
Backup etcd in Kubernetes
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: backup
namespace: kube-system
spec:
# activeDeadlineSeconds: 100
schedule: "0 */1 * * *"
jobTemplate:
spec:
@zerda
zerda / kube-flannel.yml
Created October 31, 2018 21:44
Use aliyun registry instead of quay.io
# Copied from https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
rules:
- apiGroups:
- ""
@zerda
zerda / .gitlab-ci.yml
Last active October 8, 2020 04:05
Gitlab CI for spring boot project
image: maven:3.3-jdk-8-alpine
cache:
key: "$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME"
paths:
- .m2/
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2"
@zerda
zerda / Dockerfile
Created April 12, 2017 09:11
Merge environment variables to Docker container files
FROM nginx:alpine
EXPOSE 80
RUN apk add --update --no-cache jq
ADD ./docker-entrypoint.sh /
ADD ./config.json ./index.html /usr/share/nginx/html/
ENV CONFIG_PATH=/usr/share/nginx/html/config.json
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]