Skip to content

Instantly share code, notes, and snippets.

View yszheda's full-sized avatar

Shuai YUAN yszheda

View GitHub Profile
@yszheda
yszheda / main.cpp
Created January 31, 2023 08:48
c++14 simple reflection demo
#include <utility>
#include <sstream>
#include <iostream>
#include <iterator>
#include <type_traits>
// Adopt std::void_t from c++17
template <typename... Ts>
struct make_void
{
@yszheda
yszheda / telnet-motoman.sh
Created December 10, 2019 07:46
auto connect telnet without typing username and password
#!/usr/bin/expect
spawn telnet 192.168.255.1
expect "VxWorks login:"
send "MOTOMANrobot\r"
expect "Password:"
send "MOTOMANrobot\r"
interact
@yszheda
yszheda / download_files.py
Created December 24, 2018 10:08
Download all the files with given extensions from a given url
import urllib2
from bs4 import BeautifulSoup
import requests
import urlparse
import os
extensions = ( '.pdf', '.jpg', '.png' )
url = raw_input('Input url:')
@yszheda
yszheda / check_systemtap_env.sh
Created November 10, 2017 08:30
Check SystemTap Environments
#!/bin/bash
distro="$(lsb_release --id --short)"
if [ "$distro" != "Debian" -a "$distro" != "Ubuntu" ]; then
echo Unsupported distro $distro
exit 1
fi
# 2.6.32-5-amd64
# 2.6.32-37-generic
@yszheda
yszheda / draw-figure.m
Last active August 9, 2017 02:41
Display statistics of input rawdata and draw a plot figure of it.
% Display statistics of input rawdata
% and draw a plot figure of it.
infile = input('Please enter your data file:', 's');
rawdata = load(infile);
disp('90 percentile:');
disp(prctile(rawdata, 90));
disp('99 percentile:');
disp(prctile(rawdata, 99));
@yszheda
yszheda / count_requests_by_id.sh
Last active October 8, 2016 09:25
count nginx requests by a certain POST pattern
#!/usr/bin/env bash
# The POST string is like
# \"id\"=<some number>
# Count the requests by mid
# The result is like:
# count id
# ... ...
# known search patterns:
# %22mid%22%2A
@yszheda
yszheda / sound_shrink.sh
Created June 8, 2016 03:51
Use lame to shrink sound file
#!/bin/bash
# Use lame to shrink sound file
SOUND=$1
FILE_NAME=`echo ${SOUND} | awk -F"/" '{print $NF}'`
TMP_FILE="/tmp/${FILE_NAME}"
lame -b 64 --resample 22.50 ${SOUND} ${TMP_FILE}
mv ${TMP_FILE} ${SOUND}
@yszheda
yszheda / refresh_tps.py
Last active August 8, 2016 03:01
Refresh TexturePacker tps file
#!/usr/bin/env python
# coding:utf-8
# Refresh TexturePacker *.tps
import sys
import os
import xml.sax
import cStringIO
# import string
import re
@yszheda
yszheda / auto_send_daily_mail.py
Created March 25, 2016 11:31
auto generate your daily work report by scanning your commits in the git repo, and send the mail to your boss.
#!/usr/bin/env python
# coding:utf-8
import sys
import git
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import time
SENDER = ""
@yszheda
yszheda / pre-commit
Last active November 8, 2023 09:01
svn pre-commit hook to check lua syntax errors, check lua global vars, and prevent committing large png
#!/bin/sh
# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed. Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
# [1] REPOS-PATH (the path to this repository)