Skip to content

Instantly share code, notes, and snippets.

@amboy00
amboy00 / scrollto.js
Created December 6, 2012 14:55
QUickly scroll to a div
$(document).ready(function() {
var scroll = function() {
$("html, body").scrollTop(Math.round($('#myDIv').parent('section').offset().top));
console.log($('#myDIv').offset().top);
clearTimeout(t);
}
var t = setTimeout(scroll,20);
});
@amboy00
amboy00 / qd-hreshold-scroll.js
Created December 11, 2012 14:34
Easy way to show on scroll
var myDiv = dojo.byId("myID"),
thresh = 230;
dojo.style(myDiv,{ opacity: 0, display:"none" });
dojo.connect(window,"onscroll",function(e) {
var scroll = -dojo.position(dojo.body()).y;
dojo.style(myDiv, { opacity: (Math.min(Math.max(0, scroll - thresh) / thresh, 1)), display:"inline" });
});
@amboy00
amboy00 / Angular group within
Created January 20, 2013 00:53
In Angular.js, push x number of rows into grouped repeaters. Like 7 days in a week, 30 days in a month for example.
window.myApp = this.angular.module('myApp', ['ngSanitize']);
var monthDays = ['array stuff'];
myApp.controller('MyCtrl', function($scope) {
var dates = [];
for (var i = 0; i < monthDays.length; i++ ) {
if (i % 5 == 0) dates.push([]);
dates[dates.length-1].push(monthDays[i]);
}
@amboy00
amboy00 / index.haml
Created March 27, 2013 20:55
A CodePen by Chris Williams. Sticky Div - Basic example how to make a div stick to the tippy top of a page by scrolling. Uses jQuery
%header
%h1 Say “hello” to my sticky div!
#stickySpace
#sticky
“Hello.”
%p scroll down &darr;
%p scroll down &darr;
%p scroll down &darr;
@amboy00
amboy00 / social.coffee
Created May 22, 2013 19:26
Works JUUUUUUUST fine.
js = undefined
#twitter
fjs = document.getElementsByTagName("script")[0]
unless document.getElementById("twitter-wjs")
js = document.createElement("script")
js.id = "twitter-wjs"
js.src = "//platform.twitter.com/widgets.js"
fjs.parentNode.insertBefore js, fjs
@amboy00
amboy00 / gist:5834345
Created June 21, 2013 21:11
ASCII ART Superman
<!--
_____________________________________________
//:::::::::::::::::::::::::::::::::::::::::::::\\
//:::_______:::::::::________::::::::::_____:::::::\\
//:::_/ _-"":::_--""" """--_::::\_ ):::::::::\\
//:::/ /:::::_" "-_:::\/:::::|^\:::\\
//:::/ /~::::::I__ \:::::::::| \:::\\
\\:::\ (::::::::::""""---___________ "--------" /::://
\\:::\ |::::::::::::::::::::::::::::""""==____ /::://
\\:::"\/::::::::::::::::::::::::::::::::::::::\ /~::://
#viewport
#world
.speaker
#face-1.face("data-x" = "250", "data-y" = "0", "data-z" = "0")
a(href = "#")
img(src = "http://lorempixel.com/500/500/animals/")
.speaker
//http://bost.ocks.org/mike/shuffle/
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
@amboy00
amboy00 / padding.scss
Created August 20, 2013 19:25
responsive padding.
$total-padding: 8;
@media only screen {
@for $x from 0 through $total-padding {
@for $y from 0 through $total-padding {
.small-padding-#{$x}-#{$y} {
padding-top: $x * 1em;
padding-bottom: $y * 1em;
}
}
@amboy00
amboy00 / eq.coffee
Created September 6, 2013 18:10
Are these two things equal
eq = (val1, val2) ->
i = undefined
l = undefined
return true if val1 is val2
return false if typeof val1 isnt typeof val2
if val1.length and val1.splice and val2.length and val2.splice
return false unless val1.length is val2.length
i = 0
l = val1.length