Skip to content

Instantly share code, notes, and snippets.

View cuber's full-sized avatar

Cube cuber

View GitHub Profile
@cuber
cuber / how-to-install-latest-gcc-on-ubuntu-lts.txt
Created March 14, 2022 01:43 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
@cuber
cuber / osxvpnrouting.markdown
Created March 28, 2021 12:20 — forked from taldanzig/osxvpnrouting.markdown
Routing tips for VPNs on OS X

Routing tips for VPNs on OS X

When VPNs Just Work™, they're a fantastic way of allowing access to a private network from remote locations. When they don't work it can be an experience in frustration. I've had situations where I can connect to a VPN from my Mac, but various networking situations cause routing conflicts. Here are a couple of cases and how I've been able to get around them.

Specific cases

Case 1: conflicting additional routes.

In this example the VPN we are connecting to has a subnet that does not conflict with our local IP, but has additional routes that conflict in some way with our local network's routing. In my example the remote subnet is 10.0.x.0/24, my local subnet is 10.0.y.0/24, and the conflicting route is 10.0.0.0/8. Without the later route, I can't access all hosts on the VPN without manually adding the route after connecting to the VPN:

@cuber
cuber / redis-async-connection.c
Created August 20, 2015 11:11
Async persist connection control
//
// main.c
// redisd
//
// Created by Cube on 15/8/19.
// Copyright (c) 2015年 cube. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@cuber
cuber / evhttp_client.cc
Created April 4, 2015 11:28
Concurrent Http Client of Libevent
//
// evhttp_client.cc
//
// Created by Cube on 15/4/3.
// Copyright (c) 2015年 Cube. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@cuber
cuber / ugly.js
Created December 19, 2014 08:44
886404 is ugly
var Searcher = {
a: function() {
so = this;
so.g();
window._r_ = false;
window.google = {
td: function(a, b, c) {
if (window._r_) return;
var h = c.d;
var t = h.match(/<font size="-1">[^,\d]*([,\d]+)[^,\d]*条结果[^\d]*(\d+)[^\d]*(用时 <b>(.*?)<\/b> 秒)&nbsp;<\/font>/);
@cuber
cuber / google.conf
Created December 16, 2014 07:30
ngx_http_google_filter_module.conf
server {
# ...
resolver 8.8.8.8;
location {
google on;
}
# ...
}
@cuber
cuber / proxy.pac
Last active December 26, 2016 16:00
O(1) proxy.pac file
// Generated by gfwlist2pac
// created by @clowwindy via python
// modified by @cube via native zsh
// https://github.com/cuber/gfwlist2pac
var domains = {
'dnsimple.com': 1,
'stackoverflow.com': 1,
'igvita.com': 1,
'jetbrains.com': 1,
'linost.com': 1,
@cuber
cuber / 1.matrix.php
Last active August 29, 2015 14:01
矩阵法
<?php
$e = array(
array('a1', 'a2'),
array('b1', 'b2', 'b3', 'b4'),
array('c1', 'c2'),
);
$N = count($e);
$r = array();
@cuber
cuber / 1.Q.php
Last active August 29, 2015 14:01
A->B路径求解问题
<?php
// --------------------------------------
// 通往
// 假设 [begin] -> [end] 之间有 N 个step
// 每个 step.i 又有 iM 个节点
// 需要求解 [begin] -> [end] 所有路径组合
// --------------------------------------
@cuber
cuber / crc32.sql
Created May 4, 2014 04:06
crc32 for postgresql
CREATE OR REPLACE FUNCTION CRC32(VARCHAR) RETURNS BIGINT AS
$BODY$
DECLARE
src alias FOR $1;
crc BIGINT not null default x'ffffffff'::BIGINT;
len INTEGER not null default 0;
i INTEGER not null DEFAULT 1;
table BIGINT[] not null DEFAULT ARRAY[
x'00000000'::BIGINT, x'77073096'::BIGINT, x'EE0E612C'::BIGINT, x'990951BA'::BIGINT,
x'076DC419'::BIGINT, x'706AF48F'::BIGINT, x'E963A535'::BIGINT, x'9E6495A3'::BIGINT,