Skip to content

Instantly share code, notes, and snippets.

View trkhanh's full-sized avatar

Tran Khanh trkhanh

View GitHub Profile
@trkhanh
trkhanh / install-python3-jupyter-notebooks.ps1
Created January 27, 2025 07:16 — forked from ergin/install-python3-jupyter-notebooks.ps1
Installation of Scoop, Python 3, Jupyter Notebooks, Pandas, Numpy, Matplotlib, Sklearn on Windows with Powershell
# Make sure PowerShell 5 (or later, include PowerShell Core) and .NET Framework 4.5 (or later) are installed. Then run the following steps.
# Install Scoop
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
# Note: if you get an error you might need to change the execution policy (i.e. enable Powershell) with Set-ExecutionPolicy RemoteSigned -scope CurrentUser
# Install Python 3
scoop install python
# Upgrade pip
@trkhanh
trkhanh / install-go-to-with-bash-script.md
Created October 17, 2021 05:01 — forked from d2s/install-go-to-with-bash-script.md
Installing Go with command line

NOTE: This is heavily outdated Gist snippet from 2017.


Install Go language with a Bash script

Another alternative to installing Go is to use a simple Bash script. It will download and install Go language under of your own user account.

Note that a system-wide installation might be better for some things

@trkhanh
trkhanh / PoweCLI_Script_Template_V2_Logs.ps1
Created May 31, 2021 08:25 — forked from 9to5IT/PoweCLI_Script_Template_V2_Logs.ps1
PowerShell: PowerCLI Script Template Version 2 (with logging)
#requires -version 4
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
@trkhanh
trkhanh / Contract Killer 3.md
Created January 29, 2021 08:03 — forked from joshuacerbito/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@trkhanh
trkhanh / images.py
Created December 28, 2020 10:26 — forked from nihlton/images.py
Python: Serve Images + thumbnails list as JSON. Generate missing thumbnails on the fly.
#!/usr/bin/python
from urlparse import urlparse, parse_qs
from PIL import Image
import os
import json
print "Content-Type: application/json"
print ""
@trkhanh
trkhanh / LazyImage.js
Created December 28, 2020 10:26 — forked from nihlton/LazyImage.js
Minimal Lazy Loading Image Component
import React, { useEffect, useRef, useState } from 'react'
import './LazyImage.scss'
const LazyImage = (props) => {
const [ isLoaded, setIsLoaded ] = useState(false)
const [ isVisible, setIsVisible ] = useState(false)
const { src, alt, width, height, className } = props
const placeHolderStyle = {paddingBottom: `${(height / width) * 100}%`}
const imageRef = useRef()
@trkhanh
trkhanh / getContrastColor.js
Created December 28, 2020 10:26 — forked from nihlton/getContrastColor.js
get the color (black or white) with the best contrast for the given color.
export const getContrastColor = function (bgColor) {
var color = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor
var r = parseInt(color.substring(0, 2), 16) // hexToR
var g = parseInt(color.substring(2, 4), 16) // hexToG
var b = parseInt(color.substring(4, 6), 16) // hexToB
var uiColors = [r / 255, g / 255, b / 255]
var c = uiColors.map((col) => {
if (col <= 0.03928) { return col / 12.92 }
return Math.pow((col + 0.055) / 1.055, 2.4)
@trkhanh
trkhanh / longPressEvents.js
Created December 28, 2020 10:26 — forked from nihlton/longPressEvents.js
long Press hook-like
export default function longPressEvents(callback, ms = 500) {
let timeout = null
const start = () => (timeout = setTimeout(callback, ms))
const stop = () => timeout && window.clearTimeout(timeout)
return callback ? {
onMouseDown: start,
onMouseUp: stop,
onMouseLeave: stop,
@trkhanh
trkhanh / use-local-storage.js
Created December 28, 2020 10:25 — forked from nihlton/use-local-storage.js
useLocalStorage React Hook
export default function useLocalStorage(key, initialValue, lifeSpan) {
const [storedValue, setStoredValue] = useState(() => {
try {
const item = window.localStorage.getItem(key);
const stampedValue = JSON.parse(item)
const JSONValue = stampedValue
&& stampedValue.expire > Date.now()
&& JSON.parse(stampedValue.JSONValue)
return JSONValue || initialValue;
@trkhanh
trkhanh / linkedin-auto-connect.js
Created December 26, 2020 02:38 — forked from phpenterprise/linkedin-auto-connect.js
Linkedin Auto Connect/Invite Script
(Linkedin = {
release: '1.0.5 stable',
data: {},
config: {
autoStart: true,
inspectorSpeed: 5000,
sendSpeed: 4000,
pagerSpeed: 10000,
scrollDownAuto: 600,
debug: true,