Skip to content

Instantly share code, notes, and snippets.

@kalkulus
kalkulus / unzip_all.py
Last active June 8, 2022 11:58
PYTHON: unzip all files in a directory
#!/usr/bin/python
import os, zipfile
for filename in os.listdir("."):
if filename.endswith(".zip"):
print filename
name = os.path.splitext(os.path.basename(filename))[0]
if not os.path.isdir(name):
try:
zip = zipfile.ZipFile(filename)
@kalkulus
kalkulus / jquery_get_links_by_text_and_extesion.js
Last active December 31, 2015 21:49
jQuery: get links by anchor text and extension
@kalkulus
kalkulus / gist:6462175
Created September 6, 2013 10:35
BASH: Shell script progress update
If you are writing shell scripts that manipulate big amounts of data it is helpful to the person running the script to know what is going on.
The easies way is to just print out a status line every now and then. The problem is when we have a lot of status updates with just a small change we end up with a full screen of status updates but with very little useful data.
For example, we have a list of cities that we are updating and we would like to know how far along are we.
We could print a bunch of lines like this
Updating cities: loaded 10000
Updating cities: loaded 20000
@kalkulus
kalkulus / gist:6462165
Last active December 22, 2015 10:58
PHP: shell onliner - image rotate 180 degrees
php -r '$img = imagecreatefromjpeg($argv[1]); $rotate = imagerotate($img, 180, 0); imagejpeg($rotate, basename($argv[1],".jpg")."_rotated.jpg");' my_image.jpg
@kalkulus
kalkulus / gist:6456737
Created September 5, 2013 21:53
JAVASCRIPT: Get Wordpress page content element
function getPageContent(page_type){
if (page_type == 'page'){
if ($('.page:not(body)').length)
return $('.page:not(body)');
}
else if (page_type == 'post'){
if ($('.post:not(body)').length)
return $('.post:not(body)');
else if ($('article').length)
@kalkulus
kalkulus / gist:5575383
Created May 14, 2013 11:56
JavaScript - jQuery code to harvest and format country names and country codes from http://countrycode.org/
var list = [];
$('#main_table_blue tbody tr').each(function(){
countryName = $(this).find('td:first-child a').text();
countryCode = $(this).find('td:nth-child(3)').text();
list.push('+'+countryCode+' '+countryName);
});
$('body').append('<div id="countrycodes"></div>"');
$('#countrycodes').append(list.join('<br />'));
console.debug(list);
@kalkulus
kalkulus / wordcombinator.sh
Created May 7, 2013 10:14
BASH: WordCombinator - combine dictionary words by overlapping end/start characters
#!/bin/bash
#
# Author: Dusko Petrovic <[email protected]>
#
#
# Usage:
# ./wordcombinator.sh WORD OVERLAPCHARS OVERLAPEND
# WORD - word you are looking to combine with something
# OVERLAPCHARS - number of characters to combine - default 2
# OVERLAPEND - 1 - overlap characters from the end - default
@kalkulus
kalkulus / random_ls.sh
Created May 7, 2013 10:07
BASH: List random file from dir
#!/bin/bash
ls -1 | sort -R | head -n1
@kalkulus
kalkulus / gist:5528347
Last active December 17, 2015 01:29
jQuery script to get the links to Coursera videos in a format NNN NAME::URL NNN - order of the video, so we can save them and view them in good order later NAME - name of the video URL - url of the video
$('body').append('<div id="dllinks"></div>');
pad = "000";
dllinks = $('#dllinks');
$('ul.course-item-list-section-list li').each(function(index){
str = "" + index;
padindex = pad.substring(0, pad.length - str.length) + str + ' ';
text = $(this).find('a.lecture-link').text();