Skip to content

Instantly share code, notes, and snippets.

View phanmn's full-sized avatar

phanmn

  • Ho Chi Minh city, Viet Nam
View GitHub Profile
@stephenway
stephenway / git-change-author-commit.sh
Last active March 4, 2026 01:01
Change last commit author
git commit --amend --author "Jonny Appleseed <jonny.appleseed@gmail.com>" --no-edit && \
git rebase --continue
...
git push origin master --force
@Erichain
Erichain / msconvert.js
Last active December 25, 2023 19:15 — forked from remino/msconvert.js
JavaScript: Convert milliseconds to object with days, hours, minutes, and seconds
function convertMS( milliseconds ) {
var day, hour, minute, seconds;
seconds = Math.floor(milliseconds / 1000);
minute = Math.floor(seconds / 60);
seconds = seconds % 60;
hour = Math.floor(minute / 60);
minute = minute % 60;
day = Math.floor(hour / 24);
hour = hour % 24;
return {
@jadeallenx
jadeallenx / discussion.md
Last active April 21, 2023 17:13
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

This is what the [official documentation][1] says about the terminate/2 callback for a gen_server:

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

Reason is a term denoting the stop reason and State is the internal state of the gen_server.

Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.

ffmpeg -i input-file.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output-file.webm
@jessejanderson
jessejanderson / intro-to-otp-in-elixir-resources.md
Last active September 27, 2024 08:14
Intro to OTP in Elixir - Resources
@glimpsed
glimpsed / Selective VPN traffic routes.txt
Last active April 26, 2026 17:13
How to route network traffic through a VPN (OpenVPN/TunnelBlick) ONLY for specific websites/IPs only on macOS / OS X (static routing)
Add the following line at the top of your .ovpnfile to prevent it from routing all network traffic on your Mac through
the VPN:
route-nopull
Next add the following line to allow the VPN to reroute traffic ONLY for a given IP address / domain (if you need to enable it
for a domain you can use its IP address):
route 1.2.3.4
@mmmries
mmmries / benchmarks.ex
Last active September 16, 2021 07:14
Benchmarking lbm_kv
defmodule Benchmarks do
def init do
:ok = :lbm_kv.create(Web.Job)
end
def count_entries do
IO.puts "Web.Job => #{:lbm_kv.match_key(Web.Job, :_) |> elem(1) |> Enum.count}"
end
def measure_throughput(fun, num_items) do
@ip413
ip413 / resize-video.sh
Last active December 2, 2020 07:32
Resize video to 720p MP4 with sharpen effect
#!/bin/bash
if [ -z "$1" ]
then echo "
File name to process required. File name shouldn't contain any whitespace chars.
If you want to limit cpu use for example:
cpulimit -e ffmpeg -l 200 # every thread has 100 'points'
"
else
# This line is used for testing small chunks of the file
@ttimasdf
ttimasdf / Open iterm tab here
Last active January 7, 2026 22:40 — forked from eric-hu/Open iterm tab here
Apple script to open an iterm2 tab from right-clicking on a file or folder in Finder.To use:(1) Open Automator(2) Create a new service(3) Change "Service receives selected" drop downs to "Files or folders" in "Finder"(4) Select "Run applescript" from the sidebar, then paste this script in and save
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set is_folder to (do shell script "file -b " & quoted form of (POSIX path of my_file))
if is_folder ends with "directory" then
@cvan
cvan / webgl-detect-gpu.js
Last active February 16, 2026 10:15
use JavaScript to detect GPU used from within your browser
var canvas = document.createElement('canvas');
var gl;
var debugInfo;
var vendor;
var renderer;
try {
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
} catch (e) {
}