Skip to content

Instantly share code, notes, and snippets.

@janosgyerik
janosgyerik / only-vim-can-do.md
Last active December 24, 2016 04:15
Things only Vim can do easily
  1. Works even under the most spartan conditions (in a simple remote shell window such as xterm, putty), with syntax highlighting, function folding, tabs, buffers, and all that lightning fast
  2. Delete lines matching pattern: g/pattern/d
  3. Delete lines not matching pattern: g!/pattern/d
  4. Sort buffer: :%sort
  5. Filter buffer through command :%!sort -u
  6. Delete from current line until end of file (try with a large file!)
  7. Increment numeric values: C-a, C-x
  8. Complete line pattern C-x C-l
  9. Convert a DOS file (with CRLF line endings) to UNIX: :set ff=unix (and then save it)
@janosgyerik
janosgyerik / find-pattern-in-zips.sh
Created December 16, 2013 19:17
Find a pattern in all zip files in the current directory and print a report with the number of matches, the answer for: http://stackoverflow.com/questions/20618515/how-to-find-a-pattern-in-text-files-within-zip-files-and-print-the-number-of-mat
#!/bin/bash -e
pattern=$1
for zip in *.zip; do
while IFS=: read fn count; do
echo Zip File : $zip has text file : $fn has $pattern $count times
done < <(zipgrep -c "$1" "$zip" | grep -v :0)
done
@janosgyerik
janosgyerik / winterbash2013.md
Last active December 31, 2015 12:09
stack overflow winter bash hats

http://winterbash2013.stackexchange.com/

  • 5 reviews in 5 queues
  • award bounty
  • starred chat on NYD
  • 5+ helpful flags, <= 20% declined
  • edit a cw post
  • reopen or undelete question
  • gold badge
  • first post scored 1+
#!/usr/bin/env python
import sys
s1 = sys.argv[1]
s2 = sys.argv[2]
def longest(s1, s2):
def longest(i):
suffix = s2[i:]
if s1.startswith(suffix):
@janosgyerik
janosgyerik / download-coursera-lecture-notes.bash
Created October 8, 2013 18:51
Recipe to download all lecture notes of a course on Coursera
# requirements: python, virtualenv, pip
#
# create a virtualenv -- I keep all my virtualenvs in ~/virtualenv
virtualenv --distribute ~/virtualenv/coursera
# activate virtualenv
. ~/virtualenv/coursera/bin/activate
# get the coursera downloader tool and install requirements
#!/bin/sh
cat /home/level02/.password
[email protected]
function mailme() {
file=$1
if test -f $file; then
uuencode $file $file.txt | mailx -s $file $EMAIL
else
mailx $* $EMAIL
fi
}
# usage: PW=the_pw . ~/scripts/proxy.sh"
# edit this depending on your environment
template='http://USERNAME:$PW@PROXYURL:PROXYPORT'
if test "$PW"; then
clear
echo "* note: cleared the screen for your safety"
echo "* using proxy address template: $template"
proxy_address=$(eval echo $template)

Quirks

  • Sort by movie_year ignored. Works if I specify twice, though looks stupid.

Tricks

  1. Some input items have title attribute, others have the same value in their content. How to reconcile?
@janosgyerik
janosgyerik / multilang2.md
Last active December 18, 2015 13:09
Demonstrate syntax highlighting of multiple languages within the same gist.
// where the hell my log4j settings come from??
System.out.println(Loader.getResource("log4j.properties"));
System.out.println(Loader.getResource("log4j.xml"));
-- "create" a user in MySQL
GRANT ALL PRIVILEGES ON dbname.* TO 'dbuser'@localhost IDENTIFIED BY 'userpass';