Skip to content

Instantly share code, notes, and snippets.

@brschwar
brschwar / revealing-module.js
Created July 16, 2013 14:23
Addy Osmani's Revealing Module Pattern Example
// Addy Osmani's Revealing Module Pattern Example
var myRevealingModule = function () {
var privateVar = "Ben Cherry",
publicVar = "Hey there!";
function privateFunction() {
console.log( "Name:" + privateVar );
}
@brschwar
brschwar / module-pattern.js
Last active December 24, 2015 01:29
Revealing Module Pattern
// module declaration
var Module = (function () {
var _privateFunction = function () {
// private logic
};
var publicFunction = function () {
// public logic
};
enscript -1R --line-numbers -p - --word-wrap --highlight=java --color=0 FILE.txt | pstopdf -i -o ~/Desktop/out.pdf && open ~/Desktop/out.pdf
@brschwar
brschwar / icons.sass
Last active August 29, 2015 14:15 — forked from nickawalsh/icons.sass
@import compass
$icons: sprite-map("icons/*.png")
$icons-hd: sprite-map("icons-hd/*.png")
i
background: $icons
display: inline-block
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)
background: $icons-hd
@brschwar
brschwar / Git remove ignored files
Created October 13, 2015 20:46
Remove files which are ignored in .gitignore
git rm -r --cached .
git add .
git commit -m "Removed all ignored folders and files"
git push origin master
@brschwar
brschwar / outline CSS layout
Created October 13, 2015 20:52
Visualize the outline of your CSS layout in the browser. From http://www.sitepoint.com/command-line-api-fun-profit/
[].forEach.call($$("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})
@brschwar
brschwar / respsizes.js
Created October 16, 2015 16:08 — forked from tevko/respsizes.js
Dev Tools Snippet to auto-calculate responsive image sizes value on window resize
/**
*
* Paste image class / identifier in IIFE parenthesis at end of function
*
* */
(function(i){"use strict";var img=document.querySelector(i),sizes=[];window.addEventListener("resize",()=>{var vw=Math.round(((img.offsetWidth*100)/window.innerWidth))+"vw",mq="(min-width: "+window.innerWidth+"px)",value=vw;vw!=="0vw"&&sizes.indexOf(vw)===-1&&(sizes.push(value),console.log(mq,vw))})})("PASTE CLASS OR IDENTIFIER HERE");
@brschwar
brschwar / TimerFeature.js
Last active November 12, 2015 15:20
"Timer" Feature to Optimize Your Code: Determine how long an operation takes by using "timer" feature to log the results.
function TimeTracker(){
console.time("MyTimer");
for(x=5000; x > 0; x--){}
console.timeEnd("MyTimer");
}
@brschwar
brschwar / detecting-updated-data-attribute.js
Created December 2, 2015 00:03
Detect when an element's attribute value has changed (like mutation observer): example for 'data-select-content-val' that is updated with information dynamically.
$(function() {
// Here you register for the event and do whatever you need to do.
$(document).on('data-attribute-changed', function() {
var data = $('#contains-data').data('mydata');
alert('Data changed to: ' + data);
});
$('#button').click(function() {
$('#contains-data').data('mydata', 'foo');
// Whenever you change the attribute you will user the .trigger
@brschwar
brschwar / .gitconfig
Created December 9, 2015 03:25 — forked from robmiller/.gitconfig
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"