Skip to content

Instantly share code, notes, and snippets.

View afunTW's full-sized avatar
:octocat:
import jobs

C.M. Yang afunTW

:octocat:
import jobs
View GitHub Profile

Keybase proof

I hereby claim:

  • I am afuntw on github.
  • I am afuntw (https://keybase.io/afuntw) on keybase.
  • I have a public key ASAqRqWMw9V33NOduv-D8ppUi_2z8UU1DinOLhTLLPyacwo

To claim this, I am signing this object:

@afunTW
afunTW / download_from_gdrive.bash
Created August 4, 2018 08:24
download the big file on google drive which will pop-up the virus scanner warning
download_from_gdrive() {
file_id=$1
file_name=$2
# first stage to get the warning html
curl -c /tmp/cookies \
"https://drive.google.com/uc?export=download&id=$file_id" > \
/tmp/intermezzo.html
# second stage to extract the download link from html above
@afunTW
afunTW / README.md
Last active March 7, 2024 18:18
sample code for icalendar and google calendar API

Intro

Thers's some MS-defined column in .ics that will be ignored when import .ics to google calendar. We can self modified those value and insert/update the google calendar by google calendar API.

  • icalendar: parse the .ics file
  • google-api-python-client: google calendar API

Usage

@afunTW
afunTW / queryParser.js
Created November 18, 2016 08:28
Simple parser for AND and OR to javascript regular script
/*
* input = "apple AND orange"; re = "(?=apple)(?=orange)"
* input = "apple OR orange"; re = "apple|orange"
*/
function queryParser (input) {
var re = ''
input = input.split(' ')
for (var i=0; i<input.length; ++i) {
if (input[i] !== 'AND' &&
@afunTW
afunTW / msg.py
Last active May 25, 2016 03:17
Ubuntu message wrapper
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@afunTW
afunTW / transform.cpp
Created May 2, 2016 06:42
A small transform function from vector<string> to vector<vector<int>>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;
vector< vector<int> > transform2IntVecVec (vector<string> vs){
vector< vector<int> > vvI;
@afunTW
afunTW / show.sh
Created April 18, 2016 14:53
show the query result with color
#!/bin/bash
echo To show a string within ALL files in a given directory. Updated: 2016-01-10
if [ $# -eq 0 ]
then
echo Usage: $0 [directory] [string]
else
echo Showing all \'$2\' under directory \'$1\' ...
grep -R -n --exclude-dir=node_modules --exclude-dir=lib --color=always "$2" "$1"
fi
@afunTW
afunTW / README.md
Last active March 16, 2016 08:31
Tune the simple API doc of JS

Follow the code style below

// comment
exports.youFunc = function(...){}

usage:

  1. ./tuneExports.py file1 file2 file3
@afunTW
afunTW / memRecord.sh
Last active December 28, 2015 06:47
dump memory usage per min
#!/bin/bash
echo "Recording memory usage to memoryLog..."
date >> memLog.csv
echo "USER,%CPU,%MEM,STIME,COMMAND" >> memLog.csv
while true; do
ps -ax -o user,pcpu,pmem,stime,cmd --sort -rss | head -n 6 >> tmpLog
while read -r user cpu mem stime cmd; do
if [ $user != "USER" ]; then
echo $user,$cpu,$mem,$stime,$cmd >> memLog.csv