Skip to content

Instantly share code, notes, and snippets.

View larainema's full-sized avatar

Dong Ma larainema

View GitHub Profile
@larainema
larainema / openstack-delete-instance.sh
Created August 20, 2020 13:47 — forked from frgaudet/openstack-delete-instance.sh
Delete instance from database
#!/bin/bash
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@larainema
larainema / py3.5_ubuntu_14.04.txt
Created December 16, 2015 02:24
how to install python3.5 on ubuntu 14.04
Felix Krull runs a PPA offering basically any version of Python (seriously, there is 2.3.7 build for vivid...) for many Ubuntu releases at
https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes
Do the usual:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.5
It will not overwrite your existing python3.4 which is still symlinked as python3. If you want python3.5 to be the default python3, change the symlink
@larainema
larainema / Stack.py
Created June 19, 2015 04:49
Test-driven development
Class Stack():
def __init__(self,size):
self.size=size
self.stack=[]
self.top=-1
def push(self,n):
if self.isfull():
print "Out of range"
else:
@larainema
larainema / allperms.py
Created April 14, 2015 05:59
get all possible combinations of characters given a string
def allperm(inputstr):
for i in range(len(inputstr)):
yield(inputstr[i])
for s in allperm(inputstr[:i] + inputstr[i+1:]):
yield(inputstr[i] + s)
inputstr = "abc"
for n in allperm(inputstr):
print n
import sys
from itertools import permutations
@larainema
larainema / drawline
Created July 12, 2014 01:43
use Chart.js to create line chart
<html>
<head>
<title>Line Chart</title>
<script src="scripts/Chart.js"></script>
</head>
<body>
<div style="width:60%">
<div>
<canvas id="canvas" height="450" width="600"></canvas>
</div>
@larainema
larainema / awk
Created July 12, 2014 01:35
awk use
awk 用法:awk ' pattern {action} '
变量名 含义
ARGC 命令行变元个数
ARGV 命令行变元数组
FILENAME 当前输入文件名
FNR 当前文件中的记录号
FS 输入域分隔符,默认为一个空格
RS 输入记录分隔符
NF 当前记录里域个数
@larainema
larainema / date
Created July 12, 2014 01:34
date use
date +%s 可以得到UNIX的时间戳;
用shell将时间字符串与时间戳互转:
date -d "2010-10-18 00:00:00" +%s 输出形如:1287331200
而时间戳转换为字符串可以这样做:
date -d @1287331200 "+%Y-%m-%d" 输出形如:2010-10-18
如果需要得到指定日期的前后几天,可以:
1、seconds=`date -d "2010-10-18 00:00:00" +%s` #得到时间戳
2、seconds_new=`expr $seconds + 86400` #加上一天的秒数86400
3、date_new=`date -d @$seconds_new "+%Y-%m-%d"` #获得指定日前加上一天的日前