Skip to content

Instantly share code, notes, and snippets.

Convert all ebooks in folder to mobi

for file in *.fb2; do ebook-convert "$file" "$file.mobi"; done
@andreyshuster
andreyshuster / gist:ea5e79d06ff6e36680f2608306b4b2be
Last active February 20, 2019 14:09
top ten shell commands
#!/usr/bin/env sh
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n 10
@andreyshuster
andreyshuster / gist:1264c8502ce0fa6b2206c75602b116c1
Created August 13, 2017 09:23
oneliner rename files in folder to sequental numbers
a=1; for file in *.jpg; do mv "$file" "${a}.jpg"; let a=a+1; done
@andreyshuster
andreyshuster / gist:4f1dd6cc0289746e95a8
Created March 7, 2016 08:05
delete emacs temp files
find ./ -name '*~' -exec rm '{}' \; -print -or -name ".*~" -exec rm {} \; -print
@andreyshuster
andreyshuster / gist:0b99ef2b30779fd01649
Created December 3, 2014 12:04
user_passes_test class based
# http://stackoverflow.com/questions/8082670/django-user-passes-test-decorator
class SuperuserRequiredMixin(object):
@method_decorator(user_passes_test(lambda u: u.is_superuser))
def dispatch(self, *args, **kwargs):
return super(SuperuserRequiredMixin, self).dispatch(*args, **kwargs)
class MyView(SuperuserRequiredMixin, View):
def get(self, request):
...
@andreyshuster
andreyshuster / gist:ecb683d31e11ac53bd70
Created August 21, 2014 06:59
colored tail logs. requires ack-grep
tail -f /var/log/nginx/access.log | ack-grep --flush --passthru --color --color-match=red "^.* 404 .*$" | ack-grep --flush --passthru --color --color-match=green "^.* 200 .*$"
@andreyshuster
andreyshuster / gist:4d6519396f6273c18f98
Created August 10, 2014 05:33
split string in chunks
s = %some string%
size = %chunk size%
[s[n:n+size] for n in xrange(0, len(s), size)]
:source-file ~/.tmux.conf
@andreyshuster
andreyshuster / gist:f540f1866aa7b9c7e166
Last active August 29, 2015 14:04
django form handling
@render_to('contact.html')
def contact(request):
form = ContactForm(request.POST or None)
if form.is_valid():
# обрабатываем данные. Например, делаем form.save()
# ...
return redirect('url_name', param1=value)
return {'form': form}
@andreyshuster
andreyshuster / gist:6a3afe2cb4afa4267482
Created July 29, 2014 10:20
get model fields in django
model._meta.get_all_field_names()