Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Nguyen dannguyen

View GitHub Profile
@dannguyen
dannguyen / README-xsv-split-windows.md
Last active Aug 27, 2020
How to install and use xsv to split a large CSV file (Windows)
View README-xsv-split-windows.md

How to use xsv (in Windows) to split up a CSV file too big for Excel

I wrote these instructions on how to install and use xsv – a powerful CSV-handling command-line tool, because someone asked how to deal with a data file that was too big to open in Excel or even Notepad. I didn't know how familiar the person was with installing/running downloadable .exe files or with Powershell, so I've tried to include some general instructions that hopefully are useful to even novices.

This mini-guide is not at all meant to be exhaustive as it basically shows just one of xsv's many useful functions. But if you're new to the idea of using command-line tools to do things, hopefully this can be a friendly intro to it.


Here's an example of a CSV that, at 3 million rows, is too big for Excel to open: https://burntsushi.net/stuff/worldcitiespop.csv

@dannguyen
dannguyen / bash-prompt.md
Last active Aug 19, 2020
my bash prompt with a ghost and stuff
View bash-prompt.md

this goes in my bash profile:

XRESET='\[\033[00m\]'
PROMPT_PATH="\[\033[0;33m\]\W${XRESET} \[\033[1;37m\]\$${XRESET}"
PROMPT_GHOST="༼ つ\[\033[1;33m\]°${XRESET}\[\033[1;31m\]︻\[\033[1;33m\]゜${XRESET}༽つ🐕"

export PS1="${PROMPT_GHOST} ${PROMPT_PATH} "
@dannguyen
dannguyen / normalize-ascii-google-sheet-README.md
Last active Aug 25, 2020
A modified Google App Script hack to normalize Vietnamese characters into ASCII
View normalize-ascii-google-sheet-README.md
@dannguyen
dannguyen / autotimestamp-column-in-google-sheets.md
Last active Aug 25, 2020
a Google Sheets script that automatically adds a timestamp to a corresponding row when the first column is created
View autotimestamp-column-in-google-sheets.md

How to automatically timestamp a column when a row in Google Sheets is created

Couldn't be bothered to look up the latest workout tracking app, so decided to stick to Google Sheets for now. One problem with this approach is that while it is easy on desktop GSheets to fill out a current timestamp (Command-Option-Shift-semicolon in MacOS), no such shortcut is available AFAIK in the iOS version of Google Sheets.

image

So I wrote a little custom function in Google Apps Script to do the following:

In an active Google Sheets spreadsheet, given a tab/sheet named myworkouts with a header named datetime, the following script updates a row's corresponding "datetime" column when a value is entered into a first column cell:

@dannguyen
dannguyen / nyt-local-news-sites.json
Created May 5, 2020
JSON extracted from the NYT's "Local journalism helps tell the full story" interactive https://www.nytimes.com/interactive/2020/us/support-local-journalism.html
View nyt-local-news-sites.json
[
{
"id": 0,
"name": "Adirondack Explorer",
"homepageUrl": "https://www.adirondackexplorer.org",
"supportUrl": "https://www.adirondackexplorer.org/subscription-center/new-combined-digital-and-print-subscription",
"city": "Saranac Lake",
"state": 36,
"lat": "44.329496",
"long": "-74.1312662"
View sample-aapl.tsv
date close
2-Jan-08 194.84
3-Jan-08 194.93
4-Jan-08 180.05
7-Jan-08 177.64
8-Jan-08 171.25
9-Jan-08 179.40
10-Jan-08 178.02
11-Jan-08 172.69
14-Jan-08 178.78
@dannguyen
dannguyen / _twitter-ad-impressions-dan-README.md
Last active Feb 6, 2020
Twitter's ad-impressions.js file, on how @mckinsey and @boba targeted their promoted tweets
View _twitter-ad-impressions-dan-README.md

Twitter's ad-impressions.js file, on how @mckinsey and @boba targeted their promoted tweets

The two JSON files in this gist are partial extracts from the ad-impressions.js file that Twitter gave me when I requested my personal data archive. This JSON file includes all the ads I expereinced on Twitter from December 8 2019 to Jan 8 2020.

I was just curious about ads from @McKinsey and @boba, particularly who they wanted to target, which is something that the ad-impressions.js file tells you.

tl;dr based on my personal data, I didn't really learn anything surprising. But read on for some details if you're kind of interested about social media data and ad targeting.

@dannguyen
dannguyen / cbg.sh
Last active Dec 1, 2019
cbg - a bash function (using AppleScript) to change the theme or background color of MacOS Terminal
View cbg.sh
# Helpful resources:
# https://superuser.com/questions/1188772/mac-command-to-change-the-background-color-in-a-terminal
# https://apple.stackexchange.com/questions/348762/how-to-have-a-random-background-color-in-terminal-app
# https://stackoverflow.com/questions/8063228/how-do-i-check-if-a-variable-exists-in-a-list-in-bash
cbg(){
local OCMD=""
local RED=0; local GRN=0; local BLU=0;
local THEMES="pro basic grass homebrew ocean" ## preset themes
local HELPMSG; read -r -d '' HELPMSG <<EOF
@dannguyen
dannguyen / _README.md
Last active Nov 30, 2019
hello.txt and world.txt, for dan's pydataproject-template to remotely collect
You can’t perform that action at this time.