Skip to content

Instantly share code, notes, and snippets.

View Airtnp's full-sized avatar
💭
Studying for ever

LR.X Airtnp

💭
Studying for ever
View GitHub Profile
@Airtnp
Airtnp / Program.cs
Created June 19, 2020 16:44
Shadowverse card master decryption
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace CardMasterDecompile
{
class Program
{
static void Main(string[] args)
@Airtnp
Airtnp / gist:0ba2b91e817eeb24362227547f4ff503
Created December 28, 2018 15:53
Floating number quiz
Originated from http://pdinda.org/Papers/ipdps18.pdf
a, b != NaN, a b are floating numbers
a + b = b + a ? True
a + b + c = a + (b + c) ? False
a(b + c) = ab + ac ? False
(a + b) - a = b ? False (Inf, rounding)
a * a >= 0 ? True (but false for integer arithmetic => overflow)
a overflows ? saturation, Inf (integer => wrap-around)
a := 1, b := 0, a / b = ? (Inf, will propagate to ordinary numeric)
@Airtnp
Airtnp / cpp_wtf.md
Created November 28, 2017 07:40
C++ WTF?

Cpp Quiz

Array is sure not pointer!

int arr[1]; 
int *p;
arr = xxx; // Error 
p = xxx; // OK 

int arr[10]; 
@Airtnp
Airtnp / PDF_download.py
Last active December 21, 2020 21:59
PDF_download.py
from urllib.request import urlretrieve
import requests
from bs4 import BeautifulSoup
import sys
import os
import socket
socket.setdefaulttimeout(150)
import re
class DownloadError:
@Airtnp
Airtnp / Space Optimization Tips.md
Last active September 23, 2017 04:58
Space Optimization Tips

Space Optimization Tricks

Arrange member sequence

From EECS370 we can learn alignment and know how to arrange member sequence to minimize the total memory usage. (Just arrange it from smallest to biggest).

Bit field

union {
    struct Foo {
@Airtnp
Airtnp / Time Optimization Tips.md
Last active February 2, 2020 19:28
Time Optimization Tips

Time Optimization in EECS281 Lab1

I'm just tired of constant optimization and I wrote this note to show some tricks of optimization. Note: no multithread/coroutine

1. Program

Avoid dynamic string

While keeping the structure of std::vector::resize(reserve, push_back/emplace_back) and getopt_long, instead of using dynamic std::string for storing mode, just using (char*)optarg and strcmp and return integer sign to indicate the mode. (It's simple switch (only 3 modes and 2 options), some techniques like place your case index in order and Duff's device are useless.)

@Airtnp
Airtnp / alg_ds.mdown
Created August 1, 2017 14:50
Alg-DS Idiom

Algorithm & Data Structures

[TOC]

#

  • 2-SAT
  • 2-3 Tree / 2-3-4 Tree
  • 2-3 Heap
@Airtnp
Airtnp / python_idiom.mdown
Created August 1, 2017 14:49
Python Idiom (raw has better view)

Python Idioms

#

  • *args : tuple
  • **kwargs : dict
  • [[]]*10 创建对同一个列表5次引用的列表
  • __slots__: compile-time restrict attribute
  • @/__matmul__ in py3
@Airtnp
Airtnp / cpp_idiom.md
Last active December 27, 2017 02:52
Cpp Idioms (raw has better view)

Cpp Idioms

#

  • [[...]] attribute
    • [[using namespace : attribute_list]]
    • [[noreturn]]
      • std::exit/terminate/abort, throw, infinite loop
      • never return to previous control flow, the next control flow never execute
  • asm volatile (