Skip to content

Instantly share code, notes, and snippets.

@hmil
hmil / tuples.ts
Created September 20, 2018 16:34
Well-typed variable-length tuples in TypeScript
/**
* Arbitrary-length tuples
* =======================
*
* Working with tuples of unknown length in TypeScript is a pain. Most library authors fall back on enumerating all possible
* tuple lengths up to a threshold (see an example here https://github.com/pelotom/runtypes/blob/fe19290d375c8818d2c52243ddc2911c8369db37/src/types/tuple.ts )
*
* In this gist, I'm attempting to leverage recursion to provide support for arbitrary length tuples. This has the potential
* to make some kinds of declarative APIs nicer and enhance type inference in some cases.
* This example shows how to take a variable-length tuple as an input, transform each of its types and use the resulting
@muink
muink / clowwindy-is-right.md
Last active November 22, 2023 09:13
个人感觉shadowsocks作者说的很对的一句话

shadowsocks作者说的很对的一句话与感想

个人感想:

  • 中国人很投机, 包括本人在部分情况下也是投机者. 总想不劳而获, 抄袭他人劳动成果. 想想我们学生时代的抄袭作弊之风盛行便可知... (然而为什么会这样)
  • "土皇帝"情节, 因自己在某方面上比别人强, 听听粉丝的追捧, 就觉得自己不可一世, 比别人优越, 殊不知人外有人山外有山, 而且自己在其他方面也有不如他人的地方. (然而为什么会这样)
  • 家长情节 总想要一个"家长"来管理一切, 把应该由自己解决的问题抛给别人"包办解决", 图一时之便. 久而久之结果就是并不了解你一切的"家长""包办解决"你的一切, 而你却失去了基本的思考解决问题能力, 看不到目标, 找不到方法, 只好任由"家长"摆布. 这种"爱"是现实的囚笼. (然而为什么会这样)

原文内容:

@klzgrad
klzgrad / 00-README.txt
Last active April 19, 2024 09:26
DNS compression pointer mutation
$ LD_PRELOAD=$PWD/sendmsg.so dig twitter.com @8.8.8.8
;; Warning: Message parser reports malformed message packet. <-- malformed 因为把压缩指针当作域名一部分了
;; Question section mismatch: got twitter.com/RESERVED0/CLASS256
; <<>> DiG 9.9.5-3-Ubuntu <<>> twitter.com @8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44722
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
@JoshRosen
JoshRosen / README.md
Last active August 29, 2015 14:08
Scala 2.11.1 SerialVersionUID behavior change

Confusing Scala serialization puzzle

This writeup describes a tricky Scala serialization issue that we ran into while porting Spark to Scala 2.11.

First, let's create a factory that builds anonymous functions:

class FunctionFactory extends Serializable {
  // This method returns a function whose $outer scope is this class.
  // Note that the function does not reference any variables in this scope,
@cxxr
cxxr / SearchES.java
Last active August 29, 2015 14:04
How to search Elasticsearch, with a good code contract
package me.seancassidy.search;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.action.ListenableActionFuture;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
@clowwindy
clowwindy / ssl.md
Last active April 26, 2024 03:04
为什么不应该用 SSL 翻墙

SSL 设计目标:

  1. 防内容篡改
  2. 防冒充服务器身份
  3. 加密通信内容

而翻墙的目标:

  1. 不被检测出客户端在访问什么网站
  2. 不被检测出服务器在提供翻墙服务
@wong2
wong2 / README.md
Created January 2, 2013 09:44
模拟登录人人(新)

人人的登录改版后,采用RSA加密后传输密码,该项目用于解决这种情况下人人的模拟登录

使用前先 pip install requests

@neekey
neekey / gist-blog-browser-js-error-catch-summary.md
Last active July 31, 2020 10:14
浏览器错误捕捉总结

捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。

window.onerror 讲接收3个参数:

  • msg:错误描述,比如:a is not defined
  • url:出错脚本所在的url
  • lineNumber:出错脚本的行数

本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。

@nzakas
nzakas / type-declarations.js
Created December 14, 2012 22:27
Experiment: Simple way to define types, including prototypal inheritance, in JavaScript
/*
* This is just an experiment. Don't read too much into the fact that these are global variables.
* The basic idea is to combine the two steps of defining a constructor and modifying a prototype
* into just one function call that looks more like traditional classes and other OO languages.
*/
// Utility function
function mixin(receiver, supplier) {
if (Object.getOwnPropertyDescriptor) {
@fcicq
fcicq / fcicq-question.txt
Created September 7, 2012 13:31
A simple question
有一存有整数的数组 A[n] (n <= 2^31 - 1, 但需要的话可以再扩大), 其中 0 <= i, A[i] <= n-1 且 i!=j 时 A[i]!=A[j] (即一个排列). 用你认为*最高效*的方法求 B=A^(-1) (即对范围内满足 A[B[i]]=i 的 B)