Skip to content

Instantly share code, notes, and snippets.

View NathanQ's full-sized avatar

Nathan Victor NathanQ

View GitHub Profile
@NathanQ
NathanQ / Sticky Header
Created May 5, 2013 16:42
jQuery stick to the top of the page header
$(function() {
var schtickm = $("header"), pos = schtickm.offset();
$(window).scroll(function() {
if($(this).scrollTop() > (pos.top + 10) &&
schtickm.css('position') == 'static') { schtickm.addClass('fixed'); }
else if($(this).scrollTop() <= pos.top &&
@NathanQ
NathanQ / jQuery Scroll to add or remove class
Last active June 2, 2016 21:17
jQuery window scroll fx to add or remove a class based on the div's position from top or bottom of the page.
function activeToggle ($theDiv) {
var divTop = $theDiv.offset().top - windowTop;
if (divTop > cutoffTop && divTop < cutoffBottom ) {
$theDiv.addClass('active');
}
else {
$theDiv.removeClass('active');
}
var firstlocationli = $('.location li:first').position();
$('.location li').click(function(){
$(this).addClass('selected');
$(this).siblings('li').removeClass('selected');
$(".locations").hide();
$(".locations#" + $(this).attr("id") + "_list").show();
var position = $(this).position();
@NathanQ
NathanQ / Jquery Cookie example
Last active December 18, 2015 15:59
If cookie does not exist, do something and add cookie using jQuery-cookie. https://code.google.com/p/cookies/
@NathanQ
NathanQ / Django filer template with google analytics
Created December 27, 2013 21:50
just a django template. If you use django filer / github.com/stefanfoulis/django-filer and google analytics on your web site and want to see those file clicks on the analytics reports, use this trackable link template. (formatting for legibility)
{% if object.file.url %}
<a href="{{ object.file.url }}" onclick="_gaq.push(['_trackEvent', 'File Downloads', 'Downloaded', '{{ object.file }}']);">
{% if object.title %}
{{ object.title|safe }}
{% else %}
<img src="{% file_icon object %}" alt="Download File" />
{% endif %}
</a>
{% endif %}
@NathanQ
NathanQ / mySQL
Last active January 3, 2016 12:49
Reference for mySQL root user pw reset, backup of server database, get and use the database on mac.
The root password is gone. Shut off mySQL, restart, and set new password:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
mysql
>>>> UPDATE mysql.user SET Password=PASSWORD('new easy and memorable pw') WHERE User='root';
Create new one if needed:
mysql -u projectuser -p
mysql
>>>> create database projectdb;
@NathanQ
NathanQ / Load section of html page into Bootstrap 3 modal
Created February 7, 2014 00:50
Bootstrap 3 will put a page into it's modal. Here is a way to add a section of the page to the modal using jQuery's .load().
<!-- link -->
<a href="/article.html" class="triggerModal" >
<!-- modal -->
<div id="modal" class="modal fade modal-dialog" tabindex="-1" role="dialog" aria-labelledby="yourMom" aria-hidden="true">
<div class="container">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<div class="row">
<div id="response_modal"></div>
</div>
@NathanQ
NathanQ / Track Files on Google Analytics
Created March 4, 2014 21:36
Javascript to track file downloads on Google analytics. This example takes a pdf link click and pushes the event to analytics with it's url. The setTimeout is there to give it a bit of time for the event tracking to occur before beginning the file download.
$(document).ready(function() {
$("a[href$='pdf']").click(function(event){
var href = $(this).attr('href');
_gaq.push(['_trackEvent', 'Downloads', 'File Downloaded', href]);
setTimeout(function() { window.location.href = href; }, 500 );
return false;
});
});
@NathanQ
NathanQ / squarespacePopup.js
Last active November 13, 2017 15:01
Squarespace Add Popup Video To Background Image Modules using YUI, not jQuery
YUI().use('node', 'event', function (Y) { // use squarespace's preloaded YUI instead of loading jQuery just to make a popup. add this to the footer of your page in a snippet.
var videoLink = ''; // link your links to their videos in the content.
var top = pageYOffset;
var body = Y.one('body');
var obj;
var doClose = function(e) {
e.preventDefault();
var videoContent = document.getElementById('videoContent');
videoContent.parentNode.removeChild(videoContent);
Y.one('body').removeClass('sqs-lightbox-open');
@NathanQ
NathanQ / go-down-the-page-by-btn.js
Last active May 8, 2020 18:28
Jquery scroll down with a button. Yay!
$(function() {
$('.downzy-btn').click(function() {
var mp3 = {
prefix: "data:audio/mp3;base64,",
sound: [
"SUQzAwAAAAALClRJVDIAAABkAAAAAAAAAGQgRWZmZWN0cyAtIENvbWVkeS9DYXJ0b29uIEZBUlQgV0lUSCBHT09EIEVORElORzogU3RhcnRzIGJpZyBhbmQgbG91ZCwgZW5kcyB3aXRoIGEgYmFzaWMgJ3BycnQnVFBFMQAAADQAAABEb3dubG9hZCBTb3VuZCBFZmZlY3RzIC0gU291bmREb2dzIC0gQmpvcm4gTHlubmUgRlhUQUxCAAAAGQAAAGh0dHA6Ly93d3cuU291bmRkb2dzLmNvbVRSQ0sAAAACAAAAMFRZRVIAAAAFAAAAMjAwN1RDT04AAAAcAAAAU0ZYIC0gQ2FydG9vbnM7IEh1bWFucyBGYXJ0Q09NTQAAAC8AAABlbmcAUm95YWx0eSBGcmVlIFNvdW5kIEVmZmVjdHMgLSBTb3VuZGRvZ3MuY29tVENPTQAAAAEAAABXWFhYAAAAGgAAAABodHRwOi8vd3d3LlNvdW5kZG9ncy5jb21URU5DAAAAAQAAAFRDT1AAAAAsAAAAKGMpIDIwMTAgU291bmRkb2dzLmNvbSwgQWxsIFJpZ2h0cyBSZXNlcnZlZFRPUEUAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA