Skip to content

Instantly share code, notes, and snippets.

@mapix
mapix / getlocalipaddr.sh
Created August 10, 2012 05:54
BASH: get current ip addr
OS=`uname`
IO="" # store IP
case $OS in
Linux) IP=`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
FreeBSD|OpenBSD) IP=`/sbin/ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
SunOS) IP=`/sbin/ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
*) IP="Unknown";;
esac
echo "$IP"
@mapix
mapix / 吃喝玩乐在豆瓣饭组友情提示
Created September 3, 2012 07:59
吃喝玩乐在豆瓣饭组友情提示
友情提示:
如果饭组太活跃影响到您的正常工作, 可分以下情况处理:
if 饭组很无聊 and 不想待了:
请在聊天窗口直接输入 /leave 来退出此群组
elif 希望潜水 or 不想在这个时段聊天:
在聊天窗口输入 /alertsoff 来关闭所有聊天提醒,你还可以使用 /alertson [text] 来指定只在关键词text出现的时候收到提醒
else:
在聊天窗口输入 /help 查看你需要的功能
PS:
@mapix
mapix / Find out local DISPLAY number
Created December 25, 2012 15:22
Not always does Xorg run on :0. For times like those, this script allows you to find out which it is.
export DISPLAY=$(tr '\000' '\n' < /proc/`pidof X`/cmdline | egrep '^:[0-9]+')
OR some what:
export DISPLAY=$(tr '\000' '\n' < /proc/`pidof Xorg`/cmdline | egrep '^:[0-9]+')
@mapix
mapix / List Remote Git Branches By Author
Created December 25, 2012 15:30
List Remote Git Branches By Author Place in .bash_profile
function gbl() { git for-each-ref --sort=-committerdate --format='%(committerdate) %(authorname) %(refname)' refs/remotes/origin/|grep -e ".$@"|head -n 10; }
@mapix
mapix / grep processes list avoiding the grep itself
Created December 25, 2012 15:37
grep processes list avoiding the grep itself Trick to avoid the form: grep process | grep - v grep This works because "[h]ttpd" matches only an "h" followed by "ttpd". The line that is printed by "ps aux" is "[h]ttpd" which includes the brackets, therefor not matching.
ps axu | grep [a]pache2
python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
Google URL shortener
(1) required: python-googl ( install by: pip install python-googl )
(2) get from google API console https://code.google.com/apis/console/
curl -s -d'&url=URL' http://goo.gl/api/url | sed -e 's/{"short_url":"//' -e 's/","added_to_history":false}/\n/'
googl () { curl -s -d "url=${1}" http://goo.gl/api/url | sed -n "s/.*:\"\([^\"]*\).*/\1\n/p" ;}
@mapix
mapix / Create cookies to log in to website
Created December 25, 2012 15:57
Create cookies to log in to website Generate a Netscape cookies file to use with Python's mechanize.
curl -L -d "uid=<username>&pwd=<password>" http://www.example.com -c cookies.txt
@mapix
mapix / where i'am
Created January 9, 2013 05:42
find where i'am
function ip-where { wget -qO- -U Mozilla http://www.ip-adress.com/ip_tracer/$1 | html2text -nobs -style pretty | sed -n /^$1/,/^$/p;}
ip-where `curl ifconfig.me`
@mapix
mapix / xinitrc
Created January 28, 2013 02:10
xinitrc for multi-monitor display in i3-wm
#!/bin/sh
#
# ~/.xinitrc
# Executed by startx (run your window manager from here)
# Set up screens and set background
if [ `xrandr | grep -c ' connected '` -eq 2 ]; then # dual-monitor
if [ `xrandr | grep VGA-1 | grep -c ' connected '` -eq 1 ]; then
xrandr --output LVDS-1 --auto --primary --output VGA-1 --auto --right-of LVDS-1
fi
@mapix
mapix / dot.bashrc
Last active December 11, 2015 21:18
Use in any servers for config my bash
MFS_HOME="/mfs/user/`whoami`"
source "$MFS_HOME/sysutils/config/bashrc"