Skip to content

Instantly share code, notes, and snippets.

@hoangtranwork
hoangtranwork / asdf-install-python.sh
Last active Mar 7, 2021
problem with installing python on macOS 2021-03-07 (asdf)
View asdf-install-python.sh
# this helps: https://github.com/pyenv/pyenv/wiki/Common-build-problems
AR=/usr/bin/ar asdf install python 3.9.2
View batch rename
# install rename tool
brew install rename
# add -n to dry-run
rename --camelcase -s '2001-01-0' '' -S '-' '' -s 'Eng.' '000.' -s '.Midi' '.mid' MIDI/*
rename --camelcase -s '2001-01-0' '' -S '-' '' -s 'Eng.' '000.' -s '.Pdf' '.pdf' PDF/*
rename --camelcase -s '2001-01-0' '' -S '-' '' -s 'Eng.' '000.' -s '.Mxl' '.mxl' MXL/*
View gist:312343192af1eb4db928142dee9c8f1a
Verifying my Blockstack ID is secured with the address 1Kzj9aLDdXm4LaK8Ttpv6PJDDALLZ7t1D8 https://explorer.blockstack.org/address/1Kzj9aLDdXm4LaK8Ttpv6PJDDALLZ7t1D8
View centos_logrotate
sudo bash -c "cat <<EOT > /etc/logrotate.d/api
/opt/app/*.log {
missingok
notifempty
compress
size 10k
daily
copytruncate
compress
sharedscripts
@hoangtranwork
hoangtranwork / DateUtil.kt
Last active Oct 12, 2018
Java/Kotlin DateTimeFormatter to parse Apple version of RFC3339 date returned by Apple API (Itune receipt)
View DateUtil.kt
val appleRfc3339DateFormatter: DateTimeFormatter =
DateTimeFormatterBuilder()
.appendValue(YEAR, 4).appendLiteral('-').appendValue(MONTH_OF_YEAR, 2).appendLiteral('-').appendValue(DAY_OF_MONTH, 2)
.appendLiteral(' ')
.appendValue(HOUR_OF_DAY, 2).appendLiteral(':').appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2)
.appendLiteral(' ')
.appendZoneId()
.toFormatter()
val aRfc3339DateString = "2016-03-17 03:24:38 Etc/GMT"
@hoangtranwork
hoangtranwork / open-firefox-maximized.md
Last active Oct 10, 2018
Steps to make Firefox open maximized on macOS
View open-firefox-maximized.md
  1. Get the profile folder location in about:support page

  2. Edit the file xulstore.json found in the above folder. It's a json file and we need only to edit the key main-window to something like this:

"main-window":{"screenX":"0","screenY":"0","width":"1920","height":"1080","sizemode":"maximized"}

NOTE:

  • Step 2 should be done when Firefox is not open, as it seems that the file get updated when Firefox closes.
  • Sometimes you need to put negative value to screenX if the windows is still shifted abit from the screen edge.
@hoangtranwork
hoangtranwork / main.rs
Created Oct 3, 2018
s3 bucket filtering in different ways
View main.rs
fn process(buckets: Vec<Bucket>) {
buckets.iter().filter(|b| b.name == Some(EXACT_NAME.to_string())).for_each(|b| println!("{:#?}", b));
buckets
.iter()
.filter(|b| {
let matched = b.name.as_ref().unwrap().contains(KEYWORD);
b.name.is_some() && matched
})
.for_each(|b| println!("{:#?}", b));
View ConsoleStringTable.kt
class ConsoleStringTable {
private data class Index(val row: Int, val column: Int)
private val contents = mutableMapOf<Index, String>()
private val columnSizes = mutableMapOf<Int, Int>()
private var rowCount = 0
private var columnCount = 0
@hoangtranwork
hoangtranwork / xxf.zsh-theme
Last active Dec 19, 2018 — forked from xfanwu/xxf.zsh-theme
Yet another theme for oh-my-zsh
View xxf.zsh-theme
# Copy and self modified from ys.zsh-theme, the one of default themes in master repository
# Clean, simple, compatible and meaningful.
# Tested on Linux, Unix and Windows under ANSI colors.
# It is recommended to use with a dark background and the font Inconsolata.
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
# http://xiaofan.at
# 2 Jul 2015 - Xiaofan
# Machine name.
function box_name {
@hoangtranwork
hoangtranwork / change-hostname-no-restart.md
Last active Nov 28, 2017
Without restart. Retain across ssh sessions (pernament). This also help avoiding `sudo: unable to resolve host` warning
View change-hostname-no-restart.md

Steps:

  1. edit /etc/hostname: only 1 line with the new-hostname
new-hostname
  1. edit /etc/hosts: 2 lines
127.0.0.1 localhost new-hostname
127.0.1.1 new-hostname