Skip to content

Instantly share code, notes, and snippets.

View pezy's full-sized avatar
💭
I may be slow to respond.

pezy pezy

💭
I may be slow to respond.
  • Beijing, China
View GitHub Profile
@pezy
pezy / youtube-dl.sh
Created March 11, 2018 05:32
youtube-dl use shadowsocks
youtube-dl --proxy socks5://127.0.0.1:1080

Keybase proof

I hereby claim:

  • I am pezy on github.
  • I am pezy (https://keybase.io/pezy) on keybase.
  • I have a public key ASAfWEh-NpE3eSibFcY6oB7HpwJJQs72TBmHb0J8Hvb_dwo

To claim this, I am signing this object:

@pezy
pezy / setting.json
Created July 26, 2017 03:47
VS Code custom config
{
"workbench.colorTheme": "Visual Studio Light",
"editor.formatOnType": true,
"editor.fontSize": 15,
// python
"python.linting.pylintEnabled": false,
"python.linting.pep8Enabled": true,
"python.formatting.provider": "yapf",
"python.autoComplete.addBrackets": true
@pezy
pezy / GetChapterList.js
Last active November 10, 2017 01:41
Extract the chapter list from oreilly book website
var chapter_list = document.getElementsByClassName('chapter');
var result = [];
for (var i = 0; i < chapter_list.length; ++i)
result.push(chapter_list[i].getElementsByTagName('h3')[0].innerText);
for (var i = 0; i < result.length; ++i)
document.write('- [ ] '+ result[i] + '<br>');
@pezy
pezy / Sales.cpp
Created March 7, 2017 07:40
review for CppPrimer#104
#include <iostream>
#include <string>
class Sales_data {
public:
friend std::istream& read(std::istream&, Sales_data&);
Sales_data(std::istream &is = std::cin) { read(is, *this); }
std::string bookNo;
@pezy
pezy / resize_pointer.cpp
Last active February 28, 2017 01:17
misuse of std::vector
#include <vector>
#include <iostream>
int main()
{
std::vector<int*> vec(10, new int);
for (auto p : vec)
std::cout << static_cast<void*>(p) << std::endl;
}
#define CATCH_CONFIG_MAIN
#include <string>
#include <iostream>
#include "catch.hpp"
std::string trimToString(double dValue)
{
std::string strRst = std::to_string(dValue);
while (strRst.back() == '0') strRst.pop_back();
if (strRst.back() == '.') strRst.pop_back();
@pezy
pezy / Lucy_Hedgehog
Last active April 27, 2018 04:30
10亿内质数和
Here is a solution that is more efficient than the sieve of Eratosthenes. It is derived from similar algorithms for counting primes. The advantage is that there is no need to find all the primes to find their sum.
The main idea is as follows: Let S(v,m) be the sum of integers in the range 2..v that remain after sieving with all primes smaller or equal than m. That is S(v,m) is the sum of integers up to v that are either prime or the product of primes larger than m.
S(v, p) is equal to S(v, p-1) if p is not prime or v is smaller than p*p. Otherwise (p prime, p*p<=v) S(v,p) can be computed from S(v,p-1) by finding the sum of integers that are removed while sieving with p. An integer is removed in this step if it is the product of p with another integer that has no divisor smaller than p. This can be expressed as
S(v,p)=S(v,p−1)−p(S(v/p,p−1)−S(p−1,p−1)).
Dynamic programming can be used to implement this. It is sufficient to compute S(v,p) for all positive integers v that are representable as floor(n/k) for
@pezy
pezy / nice.cpp
Created March 30, 2015 00:43
when you're upset
always:
try {
your best and;
do {
what you need to do;
} while (you still have the time);
for (opportunity; comes; only once) {
so grap the chance;
}
// given 3 points on plane (x1,y1,z1), (x2,y2,z2), (x3,y3,z3)
// get distance to (x,y,z)
double plane_exp_point_dist_3d ( double x1, double y1, double z1, double x2,
double y2, double z2, double x3, double y3, double z3, double x, double y, double z )
{
double a;
double b;
double c;
double d;
double dist;