Skip to content

Instantly share code, notes, and snippets.

@suguanYang
suguanYang / Infrastructure.js
Created March 13, 2022 12:43 — forked from sebmarkbage/Infrastructure.js
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@suguanYang
suguanYang / tooltip
Created December 1, 2021 09:54
tooltip with dynamic position
const { x: offsetLeft } = currentTarget.getBoundingClientRect();
const innerWidth = window.innerWidth;
const offsetRight = innerWidth - offsetLeft;
if (offsetLeft < TOOLTIP_WIDTH / 2) {
// if left space is too small
// --------
// |s. |
// |---- | s = offsetLeft
// | | left = -s = -
// --------
@suguanYang
suguanYang / gist:31fc7d63b6482eb6725003c787ca9e8b
Last active July 6, 2021 09:28
A fast way to check if 2 string are composed of same characters.
const alphas = {
  a: 101,
  b: 2,
  c: 3,
  d: 5,
  e: 7,
  f: 11,
  g: 13,
 h: 17,
when do migrations, if want make Backward Compatibility, you can add the new function above the old one
#!/bin/bash
set -e
curl -L -O http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip
unzip GeoLite2-Country-CSV.zip
rm GeoLite2-Country-CSV.zip
telnet exampledomain.com 25
Trying 1.1.1.1...
Connected to exampledomain.com (1.1.1.1).
Escape character is '^]'.
220-server1.exampledomain.com ESMTP Exim 4.66 #1 Wed, 01 Jua 2020 23:55:12 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
EHLO exampledomain.com
250-server1.exampledomain.com Hello [1.1.1.2]
250-SIZE 52428800
@suguanYang
suguanYang / golang snippets
Last active December 8, 2019 09:15
golang
__dirname
```
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("No caller information")
}
__dirname := path.Dir(filename)
```
@suguanYang
suguanYang / postgres-brew.md
Created October 12, 2019 07:46 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@suguanYang
suguanYang / solustion.md
Last active May 23, 2019 04:01
gem install libxml-ruby fail

The error is

Building native extensions.  This could take a while...
ERROR:  Error installing libxml-ruby:
	ERROR: Failed to build gem native extension.

    current directory: /Users/<username>/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/libxml-ruby-3.1.0/ext/libxml
/Users/<username>/.rbenv/versions/2.3.7/bin/ruby -r ./siteconf20190523-40908-1mq6z0c.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** extconf.rb failed ***
The idea of *shunting yard algorithm* is to keep operators on a stack until their operands have been parsed. The operands are
kept on a second stack. The *shunting yard algorithm* can be used to directly evaluate expressions as they are parsed, to create
a reverse Polish notation of an infix expression, or to create an AST. I'll create an AST, so my operand stacks will contain trees
The key to the algorithm is to keep the operators on the operator stack odered by precedence(lowest at bottom and highest at the top)
at least in the absence of parenthese. Before pushing an operator onto the operator stack, all higher precedence operators are cleard
from the stack. Clearing an operator consists of removing the operator from the operator stack and its operands from the operand stack
making a new tree, and pushing that tree onto the operand stack. At the end of an expression the remaining operators are put into
trees with their operands and that is that.