Skip to content

Instantly share code, notes, and snippets.

View hoangpq's full-sized avatar
Focusing

Hoang Phan hoangpq

Focusing
View GitHub Profile
@ghoseb
ghoseb / file_cols.clj
Last active April 10, 2022 17:03
Print the source-line length of a bunch of files as a histogram.
(ns file-cols.core
"Print the source-line length histogram of a bunch of files as a histogram.
Inspired by: https://gist.github.com/rsms/36bda3b5c8ab83d951e45ed788a184f4"
(:require [clojure.java.io :as io]))
(def uni-bar
"Unicode bars for histogram."
["" "▏" "▎" "▍" "▌" "▋" "▊" "▉" "█"])
(def quot-rem-8
@borkdude
borkdude / class_to_package.clj
Last active April 10, 2022 16:47
Retrieve the package string from a .class file
(require '[clojure.java.io :as io]
'[clojure.string :as str])
(defn class->package
"Implementation by Marco Marini."
[class-file]
(with-open [dis (java.io.DataInputStream. (io/input-stream class-file))]
;; skip first 8 bytes
(.skipBytes dis 8)
(let [constant-pool-count (.readUnsignedShort dis)
@gmurdocca
gmurdocca / socat_caesar_dpi.md
Last active January 22, 2024 05:08
Circumventing Deep Packet Inspection with Socat and rot13

Circumventing Deep Packet Inspection with Socat and rot13

I have a Linux virtual machine inside a customer's private network. For security, this VM is reachable only via VPN + Citrix + Windows + a Windows SSH client (eg PuTTY). I am tasked to ensure this Citrix design is secure, and users can not access their Linux VM's or other resources on the internal private network in any way outside of using Citrix.

The VM can access the internet. This task should be easy. The VM's internet gateway allows it to connect anywhere on the internet to TCP ports 80, 443, and 8090 only. Connecting to an internet bastion box on one of these ports works and I can send and receive clear text data using netcat. I plan to use good old SSH, listening on tcp/8090 on the bastion, with a reverse port forward configured to expose sshd on the VM to the public, to show their Citrix gateway can be circumvented.

Rejected by Deep Packet Inspection

I hit an immediate snag. The moment I try to establish an SSH or SSL connection over o

@joelonsql
joelonsql / JOIN FOREIGN.md
Last active February 8, 2023 23:29
SQL language proposal: JOIN FOREIGN

SQL language proposal: JOIN FOREIGN

The idea is to improve the SQL language, specifically the join syntax, for the special but common case when joining on foreign key columns.

The problem

Example below taken from PostgreSQL documentation [1]

In SQL-89, we didn't have any JOIN syntax yet, so queries were written in this way:

@PJUllrich
PJUllrich / big-o.md
Last active April 28, 2024 14:19
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements
@angerman
angerman / Installation.md
Last active February 1, 2024 11:38
Installing nix on macOS BigSur

The nixos.org website suggests to use:

sh <(curl -L https://nixos.org/nix/install)

For macOS on Intel (x86_64) or Apple Silicon (arm64) based macs, we need to use

sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
@graninas
graninas / What_killed_Haskell_could_kill_Rust.md
Last active June 5, 2024 02:57
What killed Haskell, could kill Rust, too

At the beginning of 2030, I found this essay in my archives. From what I know today, I think it was very insightful at the moment of writing. And I feel it should be published because it can teach us, Rust developers, how to prevent that sad story from happening again.


What killed Haskell, could kill Rust, too

What killed Haskell, could kill Rust, too. Why would I even mention Haskell in this context? Well, Haskell and Rust are deeply related. Not because Rust is Haskell without HKTs. (Some of you know what that means, and the rest of you will wonder for a very long time). Much of the style of Rust is similar in many ways to the style of Haskell. In some sense Rust is a reincarnation of Haskell, with a little bit of C-ish like syntax, a very small amount.

Is Haskell dead?

@ducaale
ducaale / piping-experiments.js
Last active July 7, 2020 20:41
Using ES6 Proxies to turn methods into pipe friendly functions
// .babelrc
// {"plugins": [["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }]]}
const pipeable = (class_) => new Proxy({}, {
get: (target, prop) => (
(prop in class_.prototype)
? (...args) => (receiver) => class_.prototype[prop].call(receiver, ...args)
: class_[prop].bind(class_) // https://stackoverflow.com/a/30819436/5915221
)
});
@tamuhey
tamuhey / tokenizations_post.md
Last active March 30, 2024 19:00
How to calculate the alignment between BERT and spaCy tokens effectively and robustly

How to calculate the alignment between BERT and spaCy tokens effectively and robustly

image

site: https://tamuhey.github.io/tokenizations/

Natural Language Processing (NLP) has made great progress in recent years because of neural networks, which allows us to solve various tasks with end-to-end architecture. However, many NLP systems still require language-specific pre- and post-processing, especially in tokenizations. In this article, I describe an algorithm that simplifies calculating correspondence between tokens (e.g. BERT vs. spaCy), one such process. And I introduce Python and Rust libraries that implement this algorithm. Here are the library and the demo site links:

use std::collections::HashMap;
use std::fmt;
use std::io;
use std::num::ParseFloatError;
use std::rc::Rc;
/*
Types
*/