Skip to content

Instantly share code, notes, and snippets.

View Mygod's full-sized avatar
👿
Payment is usually required for a response.

Mygod Mygod

👿
Payment is usually required for a response.
View GitHub Profile
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
#define FLOAT long double
#define epsilon 1e-8
using namespace std;
/**
* This program answers a fundamental question to life:
*
* Are there three dices A, B and C that satisfies P[A > B], P[B > C], P[C > A] > 5/9?
*
* It turns out there is.
*/
#include <cstdio>
@Mygod
Mygod / iperf.sh
Last active November 30, 2019 22:18 — forked from madeye/iperf.sh
Bandwidth test for shadowsocks
#!/bin/bash
number=$1
method=$2
ss-tunnel -k test -m $method -l 8387 -L 127.0.0.1:8388 -s 127.0.0.1 -p 8389 &
ss_tunnel_pid=$!
ss-server -k test -m $method -s 127.0.0.1 -p 8389 &
ss_server_pid=$!
@Mygod
Mygod / lserrs.cc
Created November 11, 2016 02:45
Detect errors in your device.
/**
* Detect errors in your device.
*
* Usage: sudo ./lserrs <page size in bytes> <device name>
*/
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#include <memory>
@Mygod
Mygod / test.cc
Created September 22, 2016 02:30
Proof that float multiplication is not associative
#include <iostream>
#include <random>
using namespace std;
int main() {
random_device dev;
default_random_engine engine(dev());
uniform_int_distribution<int> dist(0, 99999999);
int x, y, z, count = 0;
@Mygod
Mygod / en-US-antonyms.dic.txt
Last active September 3, 2016 01:01
Typoman dictionary
hodor - opendoor
hot - cold
close - open
yes - no
loss - gain
less - important
lose - gain
loser - gainer
evil - good
hate - love
@Mygod
Mygod / doit.sh
Last active August 14, 2016 09:48
Set up my local test server
sudo apt install apache2 php7.0-dev libapache2-mod-php7.0 php7.0-mbstring php7.0-mcrypt php7.0-xml
sudo tee -a /etc/hosts <<- hosts
127.0.0.1 zh.localhost
127.0.0.1 en.localhost
hosts
sudo vim /etc/apache2/apache2.conf
sudo vim /etc/apache2/sites-available/000-default.conf
sudo vim /etc/php/7.0/apache2/php.ini
pushd ~/Products/GitHub # or whatever dir you want
@Mygod
Mygod / github.js
Last active July 19, 2016 04:06
Get your followers score on GitHub!
// followers score = sum((1 + user.followers) / user.following) for user in your followers
// We believe a user is more valuable if he/she doesn't follow everyone he/she sees on GitHub.
function getFollowersScore(username) {
var request = new XMLHttpRequest();
request.open('get', 'https://api.github.com/users/' + username + '/followers', false);
request.send(null);
var result = 0;
var followers = JSON.parse(request.response);
var pending = followers.length;
@Mygod
Mygod / chopsticks-leftovers.cpp
Last active April 20, 2016 10:31
Chopsticks game with leftovers rule solver
/**
* Chopsticks game with leftovers rule solver.
* @author Mygod
*/
// Here's a set of rules you can customize:
#define RULE_SPLITS
//#define RULE_SUICIDAL
//#define RULE_TRANSFER
@Mygod
Mygod / nand-nor-minimizer.cc
Created March 16, 2016 15:16
nand-nor-minimizer
/**
* nand-nor-minimizer by Mygod.
*
* Test samples:
* 1000000000000000 NOR(A, B, C, D)
* 1111111111111110 NAND(A, B, C, D)
* 0000000000001110
* 1110111011101111
* 0110011011100000 My stupid assignment
* 0010011101110100 A random test sample