Skip to content

Instantly share code, notes, and snippets.

@sudu
sudu / dplyr-group-select.r
Created December 13, 2016 03:38
dplyr - select first and last row from grouped data
# from http://stackoverflow.com/questions/31528981/dplyr-select-first-and-last-row-from-grouped-data
#
# select first and last row from grouped data
# df adjusted for demonstration
df <- data.frame(id=c(1,1,1,2,2,2,3),
stopId=c("a","b","c","a","b","c","a"),
stopSequence=c(1,2,3,3,1,4,3))
# way1
import io
import os
def super_len(o):
if hasattr(o, '__len__'):
return len(o)
if hasattr(o, 'len'):
return o.len
@sudu
sudu / gist:f126257109b44d08b324
Created May 7, 2015 03:39
Python3查看变量类型
print(type(x))
@sudu
sudu / gist:bea78ce0f0186ee97167
Created May 7, 2015 03:32
Python定义变量不需要指定变量类型
x = 2
y = "Hello World"
z = -3
def bar(x):
if x == 0:
foo()
else:
foobar(x)
@sudu
sudu / getswap.sh
Created August 30, 2013 09:54
Find out what is using your swap. Thx Erik Ljungstrom, http://northernmost.org/blog/find-out-what-is-using-your-swap/
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do