Skip to content

Instantly share code, notes, and snippets.

View madcoda's full-sized avatar

Jason Leung madcoda

  • Madcoda
  • Hong Kong
View GitHub Profile
@madcoda
madcoda / AnimatedNumber.js
Created April 13, 2021 18:50
React Animated Number component using react-countup update when end changed
import React, {useEffect} from 'react';
import { useCountUp } from 'react-countup';
export default function AnimatedNumber({ value, decimals }){
const { countUp, update } = useCountUp({ start:0, end: value, decimals, duration:1.5 });
useEffect(() => {
update(value);
}, [value])
#!/bin/bash
# If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge -y nvidia-docker
# Add the package repositories
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
@madcoda
madcoda / App.js
Created May 28, 2017 04:24
React-router v4 multi layout
import React, { Component } from 'react'
import { BrowserRouter as Router, Route, Link, Match, Redirect, Switch } from 'react-router-dom'
import OverviewPage from './page/OverviewPage'
import AccountPage from './page/AccountPage'
/*
Layouts, inline define here for demo purpose
you may want to define in another file instead
*/
@madcoda
madcoda / slack.sh
Created April 6, 2017 06:40
Slack Webhook bash script
#!/bin/bash
CHANNEL="#general"
USERNAME="MyBot"
EMOJI=":ghost:"
MSG=$1
PAYLOAD="payload={\"channel\": \"$CHANNEL\", \"username\": \"$USERNAME\", \"text\": \"$MSG\", \"icon_emoji\": \"$EMOJI\"}"
HOOK=https://hooks.slack.com/services/T00000000/XXXXYYYZ/XXXXXXXX
@madcoda
madcoda / sha1dir.sh
Created October 29, 2014 14:22
Compute a SHA-1 hash of a directory (sort of)
#!/bin/sh
# arguments check
if [ -z "$1" ]
then
echo "Usage: sha1dir /path/to/directory"
exit 1
fi
# run sha1sum on every file
@madcoda
madcoda / android-screencap.sh
Created May 26, 2014 10:33
Quickly screencap on the Android device and pull to current working folder
# Add this to your ~/.bash_profile and restart the Terminal
function android-screencap(){
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
}