Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
ghost in the machine

DungSaga dungsaga

👻
ghost in the machine
View GitHub Profile
@dungsaga
dungsaga / email-regex.md
Last active January 15, 2023 00:43
practical email regex
View email-regex.md

This is my attempt to improve on the regex that match 99.99% of email from https://www.regular-expressions.info/email.html

This is a practical implementation of RFC 5322 where I omitted IP addresses, domain-specific addresses, the syntax using double quotes and square brackets.

  • Maximum length of email address is 254
  • Maximum length of the local part is 64
  • The local part must not contain double dots and must not start or end with a dot.
  • Maximum length of each domain label is 63
  • The domain part must contain at least 2 domain labels, each domain label must not start or end with a hyphen. Domain labels are separated by 1 dot.
  • The top level domain must contain only alphabet letters and must contain at least 2 letters.
@dungsaga
dungsaga / System Design.md
Created November 9, 2022 08:01 — forked from vasanthk/System Design.md
System Design Cheatsheet
View System Design.md

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@dungsaga
dungsaga / clojure-beginner.md
Created November 9, 2022 07:55 — forked from yogthos/clojure-beginner.md
Clojure beginner resources
View clojure-beginner.md

Introductory resources

View PS_shell.ps1
#Original command that was run
"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -NoProfile -Command "& {function Run-Server() { param([string]$h); $b = New-Object byte[] 8; $p = New-Object System.IO.Pipes.AnonymousPipeClientStream -ArgumentList @([System.IO.Pipes.PipeDirection]::In, $h); if ($p) { $l = $p.Read($b, 0, 8); while ($l -gt 7) { $c = [System.BitConverter]::ToInt32($b, 0); $l = [System.BitConverter]::ToInt32($b, 4); $t = $null; if ($l -gt 0) { $t1 = New-Object byte[] $l; $l = $p.Read($t1, 0, $t1.Length); $t = [System.Text.Encoding]::UTF8.GetString($t1, 0, $l) } if ($c -eq 1) { Invoke-Expression $t } elseif ($c -eq 9) { break } $l = $p.Read($b, 0, 8) } $p.Dispose() } } Run-Server -h 1860}"
#Deobfuscated command
"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -NoProfile -Command
# & is similar to Invoke-Expression except it will create an additional scope
& {
function Run-Server(){
#$h has a string value of 1860 passed from the below
@dungsaga
dungsaga / clean-up-url.js
Created July 4, 2022 07:34
clean up Youtube URLs
View clean-up-url.js
// remove "pp=" from query string of all "href" in a Youtube page
for (a of document.getElementsByTagName('a')) { a.setAttribute('href', a.getAttribute('href')?.replace(/&pp=.+/, '')) }
@dungsaga
dungsaga / merge.md
Created June 10, 2022 10:00 — forked from jt/merge.md
Merge a forked gist
View merge.md

If someone forks a gist and you'd like to merge their changes. Do this:

  1. clone your repo, I use the name of the gist

     git clone git://gist.github.com/1163142.git gist-1163142
    
  2. add a remote for the forked gist, I'm using the name of my fellow developer

     git remote add aaron git://gist.github.com/1164196.git
    
@dungsaga
dungsaga / gist:a828c4e29e2e477281ac26932cb9da7d
Created May 17, 2022 03:12 — forked from rubensa/gist:407de76194d27f763cd5e8bd235fdd5d
Public DNS Pointing To localhost (127.0.0.1)
View gist:a828c4e29e2e477281ac26932cb9da7d

Available Wildcarded DNS Domains

It turns out that some kind hearted people already set up wildcarded domains for you already. You can use any top level domain below and any subdomain of these and they will always resolve back to 127.0.0.1 (your local machine). Here's the list of ones I know about. Let me know if there are more!

  • 127-0-0-1.org.uk
  • 42foo.com
  • beweb.com
  • domaincontrol.com
  • feacebook.com
  • fuf.me - Managed by @fidian; it will always point to localhost for IPv4 and IPv6
@dungsaga
dungsaga / DNS_TO_LOCALHOST.markdown
Created May 17, 2022 03:10 — forked from tinogomes/DNS_TO_LOCALHOST.markdown
Public DNS Pointing to localhost (127.0.0.1)
View DNS_TO_LOCALHOST.markdown

Available Public Wildcard DNS Domains pointing to localhost (127.0.0.1)

It turns out that some kind hearted people already set up wildcard domains for you already. You can use any domain below and/or any subdomain of these and they currently resolve to 127.0.0.1 but could switch at any time to resolve somewhere else. Here's the list of ones I know about. Let me know if there are more!

  • localhost - It will always works. Do you know why? I hope so.
  • [*.]fuf.me - Managed by @fidian; it will always point to localhost for IPv4 and IPv6
  • [*.]fbi.com - 👏 👏 👏 👏 👏
  • [*.]localtest.me
  • [*.]127-0-0-1.org.uk
  • [*.]vcap.me
@dungsaga
dungsaga / how-to-build-HeidiSQL.md
Created April 25, 2022 22:39
How to build HeidiSQL
View how-to-build-HeidiSQL.md
@dungsaga
dungsaga / Clear-WindowsInstallerPatchInfo.ps1
Created March 24, 2022 06:13 — forked from JohnLBevan/Clear-WindowsInstallerPatchInfo.ps1
Clear-WindowsInstallerPatchInfo; cleanly/safely remove files from c:\windows\installer
View Clear-WindowsInstallerPatchInfo.ps1
#based on
# - http://blogs.msdn.com/b/heaths/archive/2007/01/31/how-to-safely-delete-orphaned-patches.aspx
# - http://www.bryanvine.com/2015/06/powershell-script-cleaning-up.html
# - https://p0w3rsh3ll.wordpress.com/2012/01/10/working-with-the-windowsinstaller-installer-object/
clear-host
function Get-WindowsInstallerPatchInfo {
[CmdletBinding()]
Param ()