Skip to content

Instantly share code, notes, and snippets.

View silviaclaire's full-sized avatar

Claire Yan silviaclaire

View GitHub Profile
import os
import re
import shutil
ROOT_DIR = "./"
# “数字_”以外的自定义文件夹写这里
CUSTOM_READ_DIR = [
"custom_folder_1",
"custom_folder_2",
@silviaclaire
silviaclaire / test.py
Created August 9, 2018 13:11
Prepare tree diagram data from cluster file list
import os
import glob
# get filename list
list = [os.path.basename(f) for f in glob.glob('./test/*')]
#['1-2.csv', '1-1.csv', '0.csv', '1-2-2.csv', '1.csv', '1-2-1.csv', '2.csv']
# remove 0.csv and extension
list.remove('0.csv')
list = [x.replace('.csv', '') for x in list]
@silviaclaire
silviaclaire / app.py
Last active August 11, 2023 19:37
Collapsible Tree Diagram using Flask and d3.js
import csv
import json
from flask import Flask, render_template
# reference: https://stackoverflow.com/questions/29631711/python-to-parent-child-json
# create a helper class for each tree node
class Node(object):
# generate new node
def __init__(self, cluster):
@silviaclaire
silviaclaire / getopt.c
Last active March 13, 2022 10:36
CL options with multiple arguments
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
void get_short_option(int argc, char **argv)
{
int c;
int i;
@silviaclaire
silviaclaire / cut-rev-sample.sh
Created May 23, 2018 07:36
Bash: Removing characters from strings
# https://www.shellhacks.com/remove-first-last-characters-strings-bash/
# File to modify
$ cat file
12345===I Love Bash===54321
12345===I Love Bash===54321
12345===I Love Bash===54321
# Remove First N Characters Of Each Line
# (delete first 5 characters of each line / starting from the 6th character)
@silviaclaire
silviaclaire / backup.sh
Created May 23, 2018 06:34
Linux: Create backup on a remotely mounted NFS file system.
#!/bin/bash
####################################
#
# Backup to NFS mount
# https://help.ubuntu.com/lts/serverguide/backup-shellscripts.html.en
#
####################################
# What to backup.
backup_files="/home /var/spool/mail /etc /root /boot /opt"
@silviaclaire
silviaclaire / backup.sh
Last active May 23, 2018 06:43
Linux: Backup directory structure
#!/bin/bash
# (https://superuser.com/questions/1095234/bash-script-to-backup-and-restore-directory-structure)
# create a tar file <Directory_Structure.tar> of the directory structure
# and a list of files <File_List.txt>
# in PWD
HomeDir=$(pwd)
BackupDIR="Backup" # Change here