Skip to content

Instantly share code, notes, and snippets.

@kapusta
kapusta / nprf.js
Created September 9, 2011 15:56
A non-polluting-recursive-function inside a Javascript module
var o = {}; /* namespace */
(function(undefined) {
this.trimPeriods = function(s) {
var return_string; /* private to trimPeriods() */
(function killCrushDestroy(s) { /* a non-polluting-recursive-function (that trims periods from the end of a string) */
if (s.substr(s.length - 1, 1) == ".") {
killCrushDestroy(s.substring(0, s.length - 1));
@kapusta
kapusta / jaahf.js
Created September 30, 2011 19:37
jQuery addressable AJAX/HTML fragments
$.ajax({
url: "/some_path/foo.php", /* a url that returns a fragment of html */
dataType: "html", /* ask for and expect html */
success: function(html){
var $fragment = $("<div/>") /* make a fragment (createDocumentFragment() won't work) */
.html(html) /* put the html into the div so we can get at stuff in jQuery */
.find("#some_id"); /* we can now .find() things! */
/* if there's a <span id="some_id" data-foo="bar"></span> in out returned html, then... */
@kapusta
kapusta / .htaccess
Created March 9, 2012 18:57
An .htaccess file for use with FontAwesome
AddType application/vnd.ms-fontobject .eot
AddType application/octet-stream .otf .ttf
AddType application/x-font-woff .woff
@kapusta
kapusta / gist:2490791
Created April 25, 2012 15:47
redefine the padding for iphone so a Bootstrap span6 will fit in the viewport
/* redefine the padding for iphone so a span 6 will fit in the viewport */
@media only screen and (max-device-width: 480px),
only screen and (-webkit-min-device-pixel-ratio: 2) {
.container-fluid {
padding-right: 10px;
padding-left: 10px;
*zoom: 1;
}
}
@kapusta
kapusta / css_pulse_ring.html
Created October 11, 2012 17:21
CSS3 Pulse Ring
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS3 Pulse Ring</title>
<style>
.gps_ring {
border: 3px solid #999;
-webkit-border-radius: 32px;
@kapusta
kapusta / gist:4960901
Created February 15, 2013 15:05
A compact jQuery "scrollto" snippet.
// Distilled from http://stackoverflow.com/questions/6677035/jquery-scroll-to-element
$outer_container.animate({
scrollTop: $("#inner_container").offset().top
}, 2000);
@kapusta
kapusta / intercept-fcty.js
Last active December 21, 2015 08:58 — forked from gnomeontherun/angularjs-interceptor.js
AngularJS interceptor factory with diff syntax from the gist I forked from. This logs everything out and is verbose as hell (dial that back as needed). In your module.config() you'll push 'intercept' onto the interceptors array by saying $httpProvider.interceptors.push('intercept'); The IIFE is in place because I keep all of my factories, servic…
// Adapted from: https://gist.github.com/gnomeontherun/5678505
(function(angular, document){
'use strict';
angular.module('YOURMODULENAMEHERE').factory('intercept', ['$q', function($q) {
console.log("intercept factory is running");
var i = {};
@kapusta
kapusta / watchers-bookmarklet.js
Last active August 29, 2015 13:56 — forked from clouddueling/bookmarklet.js
Angular watchers bookmarklet, compiled by make_bookmarklet.pl by @gruber
javascript:(function()%20{var%20root%20=%20$(document.getElementsByTagName(%27body%27));var%20watchers%20=%20[];var%20f%20=%20function(element)%20{if%20(element.data().hasOwnProperty(%27$scope%27))%20{angular.forEach(element.data().$scope.$$watchers,%20function(watcher)%20{watchers.push(watcher);});}angular.forEach(element.children(),%20function(childElement)%20{f($(childElement));});};f(root);console.log(watchers.length);}());
@kapusta
kapusta / index.html
Created April 2, 2014 20:19
basic d3 for jimdotcom
<!DOCTYPE html>
<html lang="en" ng-app="butcher">
<head>
<title>jimdotcom</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<link rel="stylesheet" href="/css/nv.d3.min.css">
@kapusta
kapusta / onDelayedKeyup.coffee
Last active August 29, 2015 14:06 — forked from davidstump/gist:d0b9f87f6a132c2991fb
a keyup debouncing directive, needs to be decaffeinated
@App.directive "onDelayedKeyup", ['$timeout', ($timeout) ->
(scope, element, attrs) ->
timer = false
element.bind "keyup", ->
$timeout.cancel(timer) if timer
timer = $timeout ->
scope.$apply attrs.onKeyup
, 500
]