Skip to content

Instantly share code, notes, and snippets.

@hoangtranwork
hoangtranwork / asdf-install-python.sh
Last active March 7, 2021 04:32
problem with installing python on macOS 2021-03-07 (asdf)
# this helps: https://github.com/pyenv/pyenv/wiki/Common-build-problems
AR=/usr/bin/ar asdf install python 3.9.2
# 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/*
Verifying my Blockstack ID is secured with the address 1Kzj9aLDdXm4LaK8Ttpv6PJDDALLZ7t1D8 https://explorer.blockstack.org/address/1Kzj9aLDdXm4LaK8Ttpv6PJDDALLZ7t1D8
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 October 12, 2018 17:14
Java/Kotlin DateTimeFormatter to parse Apple version of RFC3339 date returned by Apple API (Itune receipt)
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 October 10, 2018 08:25
Steps to make Firefox open maximized on macOS
  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 October 3, 2018 14:04
s3 bucket filtering in different ways
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));
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 December 19, 2018 22:48 — forked from xfanwu/xxf.zsh-theme
Yet another theme for oh-my-zsh
# 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 November 28, 2017 09:32
Without restart. Retain across ssh sessions (pernament). This also help avoiding `sudo: unable to resolve host` warning

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