Skip to content

Instantly share code, notes, and snippets.

@tjumyk
tjumyk / xmlToJson.js
Created April 8, 2013 16:51
A modified version of the xmlToJson function from http://davidwalsh.name/convert-xml-json, it removes the useless whitespace strings and extract attributes as normal properties so as to make the json simpler and tidier. Only for personal convenience, any ideas?
// Changes XML to JSON
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
// do attributes
if (xml.attributes.length > 0) {
//obj["attributes"] = {};
@tjumyk
tjumyk / install_dev_tools.bash
Created September 22, 2015 02:08
A simple bash script for installing essential packages for a quick start of development on a brand new Ubuntu OS
#!/usr/bin/env bash
##############################
# Add sources
##############################
# google chrome stable
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
@tjumyk
tjumyk / .bashrc
Created September 25, 2017 09:21
Python virtual environment manipulation functions for BASH
# follow other existing lines
# manipulation of virtual environments
venv()
{
local venv_home
if [ -z $1 ]; then
if [ -d ".venv" ]; then
if [ -L ".venv" ]; then
venv_home=$(readlink -f ".venv")
@tjumyk
tjumyk / fancy-motd.sh
Last active February 6, 2020 14:24
Fancy motd script for my Ubuntu
#!/bin/sh
cpu_model='Unknown CPU'
cpu_cores='?'
if [ -r "/proc/cpuinfo" ]; then
cpu_model=$(cat /proc/cpuinfo | grep 'model name' | head -n 1 | sed 's/^.*:\s*//')
cpu_cores=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
fi
mem_total='?G'
if [ -x "/usr/bin/free" ]; then
@tjumyk
tjumyk / gpuprovider.vala
Created November 4, 2017 05:15
GPU Provider for Ubuntu indicator-multiload
/******************************************************************************
* Copyright (C) 2017 Yukai Miao <tjumyk@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
@tjumyk
tjumyk / index.php
Created March 4, 2018 13:52
Simple file index for apache
<?php $title="File Index";?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<title><?=$title?></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
@tjumyk
tjumyk / conda
Last active December 27, 2023 01:38
bash auto completion for conda
# Shell auto-completion for conda
# For Ubuntu, you may put this file in /etc/bash_completion.d/ or append the contents to ~/.bashrc
_conda_auto_comp()
{
local cur opts
COMPREPLY=()
if [[ ${COMP_CWORD} == 1 ]]; then # list conda commands
cur="${COMP_WORDS[COMP_CWORD]}"
opts="clean config create help info init install list package remove uninstall run search update upgrade activate deactivate"
@tjumyk
tjumyk / setup_openvpn.sh
Last active June 20, 2024 11:10
Setup OpenVPN on Ubuntu 22.04 LTS
#!/bin/bash
set -e
SERVER_PORT="8194"
WORK_DIR="$HOME/openvpn"
EASYRSA_VERSION="3.1.7"
EASYRSA_DIR="$WORK_DIR/EasyRSA-$EASYRSA_VERSION"
CLIENT_CONFIGS_DIR="$WORK_DIR/client-configs"
@tjumyk
tjumyk / .bashrc
Created May 19, 2020 05:30
simple bash function for selecting GPU to use for CUDA
usecuda()
{
export CUDA_VISIBLE_DEVICES=$1
echo "Using cuda:$1"
}
#!/bin/bash
set -e
V2RAY_PORT=18900
NGINX_PORT_RANGE="8900-8999"
CLIENT_CFG_OUTPUT_PATH=v2ray_client.json
printf "Please make sure the firewall rules for ports 80, 443, $NGINX_PORT_RANGE have been set!\n"