Skip to content

Instantly share code, notes, and snippets.

View MaciekBaron's full-sized avatar
Recruiters, please DON'T contact me

Maciek Baron MaciekBaron

Recruiters, please DON'T contact me
View GitHub Profile
@MaciekBaron
MaciekBaron / jsmodule.sublime-snippet
Last active October 11, 2015 15:27
Sublime snippet for creating JavaScript "modules" using anonymous self-executing functions
<!--
Just simply type 'module', press Tab, then enter the name of the "module",
press Tab again and then either press Backspace to remove JQuery "support"
or press Tab once more to finish.
This creates an anonymous self-executing function which is a design pattern
that can be seen in e.g. jQuery's source code.
One of the major benefits of this pattern is that you can limit access to
variables and functions within your closure, essentially making them private
@MaciekBaron
MaciekBaron / SimpleDebug.js
Last active December 15, 2015 03:48
A very simple debug "thing" for JavaScript. You can debug messages by calling SimpleDebug.debug("My message", "some group", "log"), which will appear in the console as: [some group] My message. You can enable/disable debug, only display messages assigned to a certain group (setDebugGroup) etc.. Enjoy.
/*
* Author: Maciej Baron
*/
;(function (SimpleDebug, $, undefined) {
/*
* Simple debugging
*/
var debugEnabled = false;
@MaciekBaron
MaciekBaron / gitcommitmsg.sh
Last active December 15, 2015 04:59
Shell command to get a list of your recent commit messages from GitHub
echo Enter username; read i; echo "curl https://api.github.com/users/$i/events -s" | sh | grep message | sed -e 's/ "message": //g' -e 's/",/"/g'
@MaciekBaron
MaciekBaron / whendidifinish.sh
Last active December 15, 2015 05:09
Shows you when did you finish work (i.e. shutdown your computer) in the past
echo "last | grep shutdown | grep -v $USER" | sh | awk '{print "On "$3", "$4" "$5" finished at "$6}'
@MaciekBaron
MaciekBaron / PlaceholderFallback.js
Created April 8, 2013 11:24
A simple fallback for HTML5 placeholders (using jQuery)
if (!("placeholder" in document.createElement("input"))) {
$("[placeholder]").each(function () {
var placeholder = $(this).attr("placeholder");
$(this).val(placeholder).focus(function () {
if ($(this).val() === placeholder) {
$(this).val("");
}
}).blur(function () {
if ($(this).val().length === 0) {
$(this).val(placeholder);
@MaciekBaron
MaciekBaron / ScrollTop.js
Created April 8, 2013 11:32
A cross-browser function to retrieve the window's `scrollTop`
function getScrollTop() {
if (typeof window.pageYOffset !== 'undefined'){
return window.pageYOffset;
} else {
var iequirks = document.body;
var iedoctype = document.documentElement;
var doc = (iedoctype.clientHeight) ? iedoctype : iequirks;
return doc.scrollTop;
}
}
@MaciekBaron
MaciekBaron / HighlightTODO.py
Last active December 19, 2015 12:59
Simple plugin for highlighting TODOs and similar things
import sublime, sublime_plugin
combinations = (('todo', '(.*)TODO:(.*)', 'string'), ('fix','(.*)FIX:(.*)', 'invalid'))
class HighlightText(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
for combination in combinations:
regions = view.find_all(combination[1],0)
view.add_regions(combination[0], regions, combination[2] , '')
@MaciekBaron
MaciekBaron / gist:6306136
Created August 22, 2013 11:39
Bath renaming and numbering files in Unix (OSX flavour)
find . -name '*.jpg' | awk 'BEGIN{ a=0 }{ printf "mv %s tile%02d.jpg\n", $0, a++ }' | bash
@MaciekBaron
MaciekBaron / gist:7263887
Created November 1, 2013 10:59
Plugin for highlighting TODOs
import sublime, sublime_plugin
combinations = (('todo', '(.*)TODO:(.*)', 'variable.parameter'), ('fix','(.*)FIX:(.*)', 'invalid.depricated'), ('notabene', '(.*)NB:(.*)', 'string'))
class HighlightText(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
for combination in combinations:
view.add_regions(combination[0], view.find_all(combination[1],0), combination[2], '')
@MaciekBaron
MaciekBaron / gist:9918081
Created April 1, 2014 16:48
Renaming all files in Git to lowercase
for f in *; do git mv -f "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done