Skip to content

Instantly share code, notes, and snippets.

View dungsaga's full-sized avatar
👻
ghost in the machine

DungSaga dungsaga

👻
ghost in the machine
View GitHub Profile
@dungsaga
dungsaga / sync-time.sh
Last active December 14, 2022 22:15
sync local clock in without NTP in Linux, MacOS, Windows
# I want to sync the local clock but don't have access to any NTP server.
# Website https://time.is tells me the time difference of my system clock and I can manually adjust the local clock.
# But then I recall that a HTTP response often contains a date header with current time in GMT timezone.
# I'll use it to set the system clock with the precision of 1 or 2 seconds.
# When I need more accurate time, I can use `datetime` (or `utc_datetime`) from `http://worldtimeapi.org/api/ip.txt`
# time from worldtimeapi.org has millisecond precision, you can use it to compare with your system time:
date -uIns && time curl -s http://worldtimeapi.org/api/ip.txt | sed -n 's/^utc_datetime://p'
date -Ins && time curl -s http://worldtimeapi.org/api/ip.txt | sed -n 's/^datetime://p'
@dungsaga
dungsaga / route.sh
Last active January 14, 2020 05:59
Access remote host via a specific network interface
#!/bin/bash
# SSH can access a remote host using a specified network interface
# just use -b with local address of that network interface
ssh -b 10.20.30.40 root@12.34.56.78
# add a route to a remote host via a specified network interface
sudo ip route add 12.34.56.0/24 via 40.30.20.10 dev wlp2s0
# delete a route in the routing table
sudo ip route delete 12.34.56.0/24
// use the web page at http://marlot.org/util/calcul-de-la-cle-nir.php
// when you input the data, it will calculate the check digits (Clé de contrôle)
// ref: https://en.wikipedia.org/wiki/INSEE_code
// run this in console to get the NIR string:
v=ids=>ids.split(',').map(id=>(e=document.getElementById(id),e.value||e.textContent)).join(' ');
v('sexe,annee,mois,dept,commune,ordre,cle');
// or, patch function CalculerCleNir in http://marlot.org/util/js/global.js
// line 149: cle.innerHTML=calculCle;
@dungsaga
dungsaga / committer-date-from-author-date.sh
Last active April 13, 2021 03:44
set committer date to author date for the latest git commit
#!/bin/bash
# set committer date to author date for the latest git commit
env GIT_COMMITTER_DATE=$(git log -1 HEAD | grep Date: | cut -d' ' -f2-) git commit --amend --no-edit --date=$GIT_COMMITTER_DATE
#!/usr/bin/fish
# fish shell use (...) instead of $(...)
env GIT_COMMITTER_DATE=(git log -1 HEAD | grep Date: | cut -d' ' -f2-) git commit --amend --no-edit --date=$GIT_COMMITTER_DATE
#!/bin/bash
@dungsaga
dungsaga / integer-list-generator.js
Last active April 7, 2023 03:43
integer list generator in JS
// while reading "Why List Comprehension is Bad" (http://xahlee.info/comp/list_comprehension.html),
// I notice that JS don't have integer list generator like 0..9 or range(0,9)
// I wanna see if a one-liner can generate 1 list of integer i where 0 <= i < 9
// ref: https://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-a-range-within-the-supp
// benchmark: https://jsbench.me/tykijeavk9/1 (from https://stackoverflow.com/questions/3746725/how-to-create-an-array-containing-1-n/65244361#65244361)
// using generator
function*(){let i=0;while(i<9)yield i++}()
function*(i=0){while(i<9)yield i++}()
@dungsaga
dungsaga / st4-changelog.md
Last active July 14, 2020 07:26 — forked from jfcherng/st4-changelog.md
Sublime Text 4 changelog just because it's not on the official website yet.
@dungsaga
dungsaga / JavaScript-Bookmarklet-in-IE.md
Created September 9, 2020 03:28
JavaScript Bookmarklet in IE

Each bookmark is stored in a shortcut file under %USERPROFILE%/Favorites It looks like this:

[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,15
[InternetShortcut]
URL=javascript:alert('oh yea')
IDList=
[Bookmarklet]
ExtendedURL=javascript:alert('oh yea')
@dungsaga
dungsaga / funny_acronym_php.md
Last active April 12, 2023 12:24
funny acronym: what does PHP stand for?

Prrr Home Page

  • Pretty Home Page (some people think this is the initial meaning of PHP)
  • Professional Homepage Power
  • Private Home Page
  • Personal Home Page (the original name in the announcement "Announce: Personal Home Page Tools (PHP Tools)")
  • Phucking Home Page

Programmable

@dungsaga
dungsaga / spleeter.md
Last active March 17, 2024 20:00
Voice removal AKA karaoke creator
@dungsaga
dungsaga / GetNthBusinessDay.sql
Created April 13, 2021 17:55
return Nth business date after or before start date (excluding Saturday and Sunday) using PL/SQL
-- return day of week (Mon=1, Tue=2, ... Sun=7)
FUNCTION WeekDay(weekdayName IN VARCHAR2) RETURN INTEGER AS
weekDay INTEGER;
BEGIN
SELECT DECODE(weekdayName, 'Mon', 1, 'Tue', 2, 'Wed', 3, 'Thu', 4, 'Fri', 5, 'Sat', 6, 'Sun', 7) INTO weekDay FROM Dual;
RETURN weekDay;
end WeekDay;
--End function return day of week
-- return Nth business date after or before start date (excluding Saturday and Sunday)