Skip to content

Instantly share code, notes, and snippets.

View theharveyz's full-sized avatar
🕶️
NOOP

HarveyZ theharveyz

🕶️
NOOP
View GitHub Profile
@evenX86
evenX86 / redis_key_sizes.sh
Last active March 16, 2018 05:55 — forked from epicserve/redis_key_sizes.sh
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@evenX86
evenX86 / AggArrayJava.java
Last active March 16, 2018 05:48
spark udaf to sum array by java
package udaf;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.expressions.MutableAggregationBuffer;
import org.apache.spark.sql.expressions.UserDefinedAggregateFunction;
import org.apache.spark.sql.types.DataType;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import math
class Tree:
def __init__(self, seq):
self.root = seq[0]
self.left_seq, self.right_seq = [], []
if len(seq) == 1:
self.leaf = True
self.left = None
@simsicon
simsicon / kmp.py
Last active December 5, 2016 03:21
def kmp(text, pattern):
partial = [0]
for i in range(1, len(pattern)):
j = partial[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = partial[j - 1]
partial.append(j + 1 if pattern[j] == pattern[i] else j)
ret = []
@kxxoling
kxxoling / six.md
Last active April 20, 2017 09:02
Python 2-3 兼容库 six

由于 Python 在 2-3 版本的升级过程中的激进演变,导致了应用的兼容困难, 很多第三方库为了同时兼容 Python 2 和 3 不得不使用一些难看的 patch 来解决兼容性问题。 比较常见的做法是自己编写 _compat.py(compatibility 的缩写) 或者直接使用 six 库。

six 支持 Python 2.5+ 版本,你可以引用它,也可以将其直接复制到代码库中。

six 是 2*3 的意思,之所以使用 2*3 而不是 2+3 ,是因为 five 这个名字已经被 Zope Five 所使用。

官方文档:six

@MoOx
MoOx / index.js
Last active April 4, 2025 01:05
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
@cevaris
cevaris / struct_as_map_key.go
Last active October 20, 2023 03:18
Golang: Using structs as key for Maps
package main
import "fmt"
type A struct {
a, b int
}
func MapStructValAsKey(){
// Notice: We are using value of `A`, not `*A`
@benjamingr
benjamingr / gist:0237932cee84712951a2
Last active October 6, 2023 08:31
Promise unhandled rejection tracking global handler hook

Possibly Unhandled Rejection NodeJS Promise Hook

###Unhandled Rejection Tracking

Several promise libraries such as bluebird and when as well as some native promise implementations offer potentially unhandled rejection tracking. This means that the following:

Promise.reject(new Error("err")); // never attach a `catch`
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy
(function () {
var dateTimeController = function ($scope, $rootScope) {
$scope.vm = {
message: "Bootstrap DateTimePicker Directive",
dateTime: {}
};
$scope.$watch('change', function(){
console.log($scope.vm.dateTime);
});