Skip to content

Instantly share code, notes, and snippets.

View HeLiBloks's full-sized avatar

Henrik Lindgren HeLiBloks

  • Stockholm
View GitHub Profile
@HeLiBloks
HeLiBloks / vimtags.sh
Created April 20, 2016 15:33
generate ctags file for use in VimL script
#!/bin/bash
#vim:set et sw=4 ts=4 foldenable foldmethod=marker:
tagsSourcedVimFiles(){
# create tagfile containing sourced scriptfiles
[ -f /tmp/tagtemp ] && rm -f /tmp/tagtemp
nvim -c"redir => message|silent scriptnames|redir END" \
-c"silent put=message" \
-c"w /tmp/tagtemp|q!" &&\
cut -f2 -d':' /tmp/tagtemp\
@HeLiBloks
HeLiBloks / curl.sh
Last active April 15, 2016 14:04
curl scripts
#!/bin/sh
#show size of remote file, should fetch only header
curl 'http://www.ruhbarbdownloads.remote'\
--silent -H 'Accept-Encoding: gzip,deflate'\
--write-out 'size_download=%{size_download}\n'\
--output /dev/null
#show header
curl -sI 'http://www.ruhbarbdownloads.remote' #| awk '/Content-Length/ { print $2 }'
@HeLiBloks
HeLiBloks / date.sh
Created April 5, 2016 17:22
convert dates in nix
#nix date conversion
# time2unixStamp
date -d "2016/03/01 01:00:00" "+%s"
#readline
while read line ; do echo $line\;$(date -d "$t" "+%s") ; done < $1
#unixTime2human
date -d @1458636426
awk '{ print strftime("%c", $0); }' $1
@HeLiBloks
HeLiBloks / Regexp.sh
Last active April 4, 2016 21:51
Regexp for each case
# Dates YYYY-MM-DD HH:MM:SS
grep -oP '[1-2][90][0-9]{2,2}([-/ ])[0-2][0-9]\1[0-2][0-9] [0-2][0-9]([:])[0-6][0-9]\2[0-6][0-9]'
#
perl -pe 's/[^[:ascii:]]//g'
@HeLiBloks
HeLiBloks / htmlTable.sh
Last active April 4, 2016 13:03
html table from csv file with sed
#!/bin/sh
sed -re '
s/^.*$/<tr>\n<td>&<\/td>\n<\/tr>/g
s/[,]/<\/td>\n<td>/g
1i <table style="width:100%">
$a\<\/table>' "$1"
@HeLiBloks
HeLiBloks / urldecode.sh
Created March 31, 2016 12:13
decodes urls to human readable format
#!/bin/sh
sed -re 's/[%]([[:xdigit:]]{,2})/\\\x\1/g' "$1"| xargs -0 printf '%b'
@HeLiBloks
HeLiBloks / awk.sh
Last active October 18, 2016 18:01
gawk awk hawk
#print occurrance off ;,|[:TAB:]
#this might be the delim
awk -vFS="" '{for(i=1;i<=NF;i++){ if($i~/[,;| ]/) { w[tolower($i)]++} } }END{for(i in w) print i,w[i]}' file.csv |sort -n|head -1|cut -f1 -d" "
#find longest line
awk -F"$DELIM" '{ if ( length > L ) { L=length} }END{ print L}' $1
#fix commas after quotes, good for cleaning csv files
awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' $1
@HeLiBloks
HeLiBloks / ctags
Last active March 31, 2016 19:13
ctags lang def for xml
--langdef=XML
--langmap=XML:.xml .xmla .cube .dim .sln .database .dwproj .dwproj.user .partitions .ds .dsv
--regex-XML=/id="([a-zA-Z0-9_]+)"/\1/d,definition/
--regex-sh=/^.*[ \t]*([A-Za-z][A-Za-z0-9_]*)=[".]*/\1/k,tasks/
--languages=+sh
@HeLiBloks
HeLiBloks / vim_makeScript_sh.sh
Last active February 20, 2016 20:30
HeLis vim build script
#!/bin/slurp
# modeline and info {{{1 #
# vim: set ft=sh foldmethod=marker foldmarker={{{,}}} foldenable
#######################################################################
# build script for vim. #
# see http://vim.wikia.com/wiki/Building_Vim #
#######################################################################
# 1}}} #
# remove vim first {{{ #
@HeLiBloks
HeLiBloks / squid_commands.sh
Last active May 4, 2016 09:38
Useful squid commands
find . | xargs head -n1 | strings | grep :// > squid-urls.txt #list of urls in squid cache
#purge pattern from cache
for x in `cat squid-urls.txt | grep foo`; do
squidclient -m PURGE $x ;
done
#format the dates
perl -p -e 's/^([0-9\.]*)/"[".localtime($1)."]"/e' *.log