Skip to content

Instantly share code, notes, and snippets.

@GNHua
GNHua / Fs2HttpClient.scala
Created July 1, 2023 07:31
A Http client implemented with fs2 streaming
import scala.concurrent.duration.{DurationInt, FiniteDuration}
import cats.effect.{IO, Resource}
import fs2.io.file.{Files, Path}
import fs2.{Stream, text}
trait HttpClient {
def getBodyFrom(url: String): Stream[IO, Byte]
}
@GNHua
GNHua / install_app.sh
Last active June 25, 2020 16:50
Mac OSX - install app in terminal
# source: https://apple.stackexchange.com/questions/73926/is-there-a-command-to-install-a-dmg
# usage: installdmg https://example.com/path/to/pkg.dmg
function installdmg {
set -x
tempd=$(mktemp -d)
curl $1 > $tempd/pkg.dmg
listing=$(sudo hdiutil attach $tempd/pkg.dmg | grep Volumes)
volume=$(echo "$listing" | cut -f 3)
if [ -e "$volume"/*.app ]; then
@GNHua
GNHua / install_anaconda.md
Created April 6, 2020 01:17 — forked from kauffmanes/install_anaconda.md
Install Anaconda on Windows Subsystem for Linux (WSL)

Note: $ denotes the start of a command. Don't actually type this.

Steps to Install Anaconda on Windows Ubuntu Terminal

  1. Install WSL (Ubuntu for Windows - can be found in Windows Store). I recommend the latest version (I'm using 18.04) because there are some bugs they worked out during 14/16 (microsoft/WSL#785)
  2. Go to https://repo.continuum.io/archive to find the list of Anaconda releases
  3. Select the release you want. I have a 64-bit computer, so I chose the latest release ending in x86_65.sh. If I had a 32-bit computer, I'd select the x86.sh version. If you accidentally try to install the wrong one, you'll get a warning in the terminal. I chose Anaconda3-5.2.0-Linux-x86_64.sh.
  4. From the terminal run wget https://repo.continuum.io/archive/[YOUR VERSION]. Example: $ wget https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
  5. Run the installation script: $ bash Anaconda[YOUR VERSION].sh ($ bash Anaconda3-5.2.0-Linux-x86_64.sh)
  6. Read the license
@GNHua
GNHua / Tree view of a directory or folder in Windows.bat
Created November 15, 2018 21:36
Tree view of a directory or folder in Windows
:: Go to folder in command prompt
tree /f > tree.txt
:: Use MS Word to open "tree.txt"
:: The dialog box "File Conversion - tree.txt" will open
:: For "Text encoding" tick the "MS-DOS" option
@GNHua
GNHua / get_shell_script_absolute_path.sh
Last active November 11, 2018 06:15
Get the absolute path of a shell script when running it
#! /bin/bash
# Source here:
# https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself#4774063
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
echo $SCRIPTPATH
@GNHua
GNHua / git_bash_force_password.txt
Created June 22, 2018 02:47
Force Git bash to ask password
git -c credential.helper= clone https://github.com/ttaylorr/lfs-gfw-bug.git
@GNHua
GNHua / download_youtube_audio.py
Last active March 22, 2018 23:10
Download YouTube Audio
from pytube import YouTube
import os
import subprocess
def download_yt_audio(link):
yt = YouTube(link)
yt.register_on_progress_callback(show_progress_bar)
# Download mp4 audio. If it does not exist, download lowest resolution mp4 video.
@GNHua
GNHua / simple_http_server_with_auth.py
Created January 5, 2018 00:57
Simple Python HTTP server with authentication
# Python 3.6
import http.server
import base64
class CustomServerHandler(http.server.SimpleHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
@GNHua
GNHua / download.py
Created January 4, 2018 18:37
Download files from URL in Python
import urllib.request
from datetime import datetime
def download(dwn_link, filename):
try:
print("Downloading starts...")
print('***', filename, '***')
print(datetime.now())
urllib.request.urlretrieve(dwn_link, filename)
print("Download completed..!!")