Skip to content

Instantly share code, notes, and snippets.

View dungwinux's full-sized avatar

Nguyễn Tuấn Dũng dungwinux

View GitHub Profile
@dungwinux
dungwinux / type.hs
Created March 2, 2021 21:09
Functional with Haskell
h f g x = f (f g) (g x) -- JS equivalent: let h = f => g => x => f(f(g))(g(x))
a y x = y x + 1
b x = x * 2
h a b 1 -- Guess the value
@dungwinux
dungwinux / lib220.d.ts
Last active April 5, 2021 23:55 — forked from stephanlensky/lib220.d.ts
Ocelot IDE lib definition + IntelliSense unlock script
// lib220
/**
* Pixel: The type of each element in a canvas.
* Each number in pixel represents R, G, B, respectively.
*/
type Pixel = [number, number, number];
interface Canvas {
/**
* The drawLine function draws a line on the canvas that stretches from a designated
@dungwinux
dungwinux / themisCfg.js
Created March 23, 2019 02:18
Javascript version of Themis config uncompresser
const zlib = require("zlib");
const fs = require("fs");
function decode(s) {
let dec = zlib.inflateSync(s);
let res = dec.toString("utf8");
return res;
}
function encode(s) {
@dungwinux
dungwinux / themisCfg.py
Created March 15, 2019 12:44
Encode and decode Themis config files
import zlib
from sys import argv
def decode(s):
dec = zlib.decompress(s)
res = dec.decode("utf-8")
return res

Async/await - Giải thích

  • Chương trình chạy: A cần làm đề cương
  • async: A gửi tin nhắn cho B, nhờ làm hộ đề cương rồi chụp
  • await: A chờ B gửi bài
  • new promise: B hứa sẽ làm đề cương giúp A
    • promise<pending>: B làm đề cương giúp A
    • promise<fulfilled>: B hoàn thành đề cương và chụp vở gửi cho A
  • promise: B không làm đề cương giúp và để lại chữ "seen" cho A
g++ -CC -P -undef -nostdinc -dDI -E "$1"
g++ -CC -P -undef -nostdinc -dDI -E "%1"
@dungwinux
dungwinux / rev.cpp
Last active June 14, 2018 08:15
Reverse string
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define _ ;
#define __ int
#define ___ main
#define ____ (
#define _____ )
@dungwinux
dungwinux / tasks.json
Last active July 21, 2018 14:18
VSCode C++ tasks script
{
"version": "2.0.0",
"tasks": [
{
"label": "Build C++17",
"group": "build",
"command": "g++",
"args": [
"-std=c++17",
"-O3",
@dungwinux
dungwinux / makegif.bat
Last active April 21, 2018 06:12
Make gif with ffmpeg and gifski
@echo off
set _excode=
REM Check commands if available
where ffmpeg.exe
set ffmpeg_check=%errorlevel%
where gifski.exe
set gifski_check=%errorlevel%