Skip to content

Instantly share code, notes, and snippets.

@stinoga
stinoga / lazy.js
Created June 26, 2013 19:49
Lazy Loading Images based on adjacent section headers. Dependencies: JQuery, Lo-Dash
// Defer Image loading until parent headers come into view
// =======================================================
// Setup vars
var win = $(window),
lazyScrollDelta = 200,
headerIndex = 0,
sectionCount = all_products.length - 1;
// Bind scroll event
@stinoga
stinoga / decode.js
Created July 30, 2013 20:39
Decode cookie, and parse into JSON object w/ JQuery
$.parseJSON(decodeURIComponent($.getCookie('COOKIE_NAME')));
@stinoga
stinoga / .htaccess
Last active December 20, 2015 10:49
Busting cache with Grunt and Apache.
# To understand why this is important and a better idea than `*.css?v231`, read:
# http://stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
@stinoga
stinoga / Rabbits.js
Created December 6, 2013 05:07
Applying arguments to objects. Works especially well if those objects are rabbits.
// define the function to see what the rabbits say
function speak (line) {
console.log("The ", this.adjective, " rabbit says ", line);
}
// define some rabbit objects
var whiteRabbit = {adjective: "white", speak: speak};
var fatRabbit = {adjective: "fat", speak: speak};
// apply an array of arguments to our fatter of the two rabbit objects
@stinoga
stinoga / index.js
Created December 23, 2013 18:05
Replacing query string parameter values.
// Update the appropriate href query string parameter
function paramReplace(name, string, value) {
// Find the param with regex
// Grab the first character in the returned string (should be ? or &)
// Replace our href string with our new value, passing on the name and delimeter
var re = new RegExp("[\\?&]" + name + "=([^&#]*)"),
delimeter = re.exec(string)[0].charAt(0),
newString = string.replace(re, delimeter + name + "=" + value);
return newString;
@stinoga
stinoga / lazyDirective.js
Last active January 4, 2016 21:19
Angular Lazy Load
// Lazy load directive, taken from http://slid.es/djsmith/deep-dive-into-custom-directives
directive('myLazyLoad', function() {
return {
transclude: 'element',
priority: 1200, // changed needed for 1.2
terminal: true,
restrict: 'A',
compile: function(element, attr, linker) {
return function (scope, iterStartElement, attr) {
@stinoga
stinoga / command.sh
Last active October 23, 2023 16:16
Sublime Command line
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin
@stinoga
stinoga / console.js
Last active August 29, 2015 13:57
Get Titles on the Page (jQuery)
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
var array = []
$(".title > a").each(function() {
array.push($(this).text());
});
# generate ssh key
ssh-keygen -t rsa
# copy public key to clipboard
pbcopy < ~/.ssh/id_rsa.pub
@stinoga
stinoga / console.js
Created December 27, 2014 22:18
Save console output to a file
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'