Skip to content

Instantly share code, notes, and snippets.

@jvanja
jvanja / JavaScript: PubSub
Last active August 29, 2015 14:01 — forked from cassiano-gists/gist:4141404
JavaScript: Pub/Sub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
// Usage
$(document.body).on( 'click', function() {
@jvanja
jvanja / 755_On_All.sh
Created October 30, 2015 08:45
Unix FIND all files that do not have 755 permision and CHMOD 755 on them
find . -not -perm 755 -type f -exec chmod 755 {} \;
@jvanja
jvanja / Top10.sh
Created October 30, 2015 08:47
Find 10 largest files under current directory and show them
find . -type f -exec ls -s {} \; | sort -n -r | head -10
@jvanja
jvanja / Rename All.sh
Created November 2, 2015 16:16
Find all files of type of HTML and change their names to index.html
find . -name "*.html" -exec bash -c 'cp "{}" "$(dirname "{}")"/index.html' \;
@jvanja
jvanja / Git undo commit
Created April 12, 2014 22:23
Git undo commit
# undo commit and REVERT the files to the last HEAD
git reset --hard HEAD~1
# undo commit but PRESERVE the files before the last commit
git reset HEAD~1
@jvanja
jvanja / Regex - in between
Last active December 27, 2015 14:59
Regex for search and replace in between two strings: string 'start' and string 'end', using 'look ahead' and 'look behind'.
(?<=start)(.*)(?=end) // lazy - it will select until LAST occurence
(?<=start)(.*?)(?=end) // not lazy - it will select until FIRST occurence
@jvanja
jvanja / awk_examples.sh
Created January 12, 2016 09:28
Useful awk examples
#searches for 'search_term' and prints all columns
awk '/search_term/' file.txt
#searches for 'search_term' and prints columns 1 and 4 separated with tab (the first column is index 1)
awk '/search_term/ {print $1 "\t" $4}' file.txt
#searches for 'search_term' and prints the number of occurances
awk '/search_term/{++cnt} END {print "Count = ", cnt}' file.txt
#print lines having more than 18 characters
@jvanja
jvanja / list_process_using__port.sh
Created June 23, 2016 09:40
List processes using the port
lsof -n -i4TCP:[PORT_NUMBER]
@jvanja
jvanja / largest_20.sh
Created December 14, 2016 09:50
List the 20 largest files or folders under the current directory
du -ma | sort -nr | head -n 20
@jvanja
jvanja / functions.php
Created March 13, 2017 08:54 — forked from martynchamberlin/functions.php
How to get_the_content() with formatting
<?php
/**
* Instead of calling get_the_content(), call this function instead, and it'll all be good
*/
function get_the_content_with_formatting()
{
ob_start();
the_content();
$the_content = ob_get_contents();