Skip to content

Instantly share code, notes, and snippets.

Avatar
🐛
squashin bugs.

nick comer nkcmr

🐛
squashin bugs.
View GitHub Profile
@nkcmr
nkcmr / spdy.js
Created Feb 11, 2014
replacing https with spdy
View spdy.js
var express = require("express");
var app = express();
//BEFORE
var https = require("https");
https.createServer({ /*options and ssl stuff*/ }, app).listen(443);
//AFTER
var spdy = require("spdy");
spdy.createServer({ /*options and ssl stuff*/ }, app).listen(443);
@nkcmr
nkcmr / gist:3853630202c157fc7686
Created May 16, 2014
please-uphold-strict-net-neutrality.eml
View gist:3853630202c157fc7686
Date: Fri, 16 May 2014 11:50:25 -0400
From: Nick Comer
To: openinternet@fcc.gov
Message-ID: <etPan.537633c1.6b8b4567.2c2@alpha.local>
Subject: Please Uphold Strict Net Neutrality
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
I could write a drawn out, multi-page essay on the reasons that net
View gist:9b9ec0a62481ca387ef9

Send a request to: http://giphy.com/services/oembed/?url=http://giphy.com/gifs/ijJ0Ltz4UuD4s, and it returns this:

{
  "width": 360,
  "author_url": "http://giphy.com",
  "title": "Idk Animated GIF",
  "url": "http://giphy.com/gifs/zLOr4ChnIorxS",
  "image": "https://media3.giphy.com/media/zLOr4ChnIorxS/giphy.gif",
  "provider_url": "http://giphy.com/",
@nkcmr
nkcmr / scrollIntoView.js
Created Feb 4, 2015
$.fn.scrollIntoView
View scrollIntoView.js
define([], function() {
function stripWrapper(ele) {
return (ele instanceof jQuery || ele instanceof angular.element) ? ele[0] : ele;
}
function getRect(el) {
el = stripWrapper(el);
return _.pick(el.getBoundingClientRect(), 'top', 'left', 'bottom', 'right', 'width', 'height');
}
@nkcmr
nkcmr / the-beast-of-a-regex.js
Created Mar 16, 2015
best working email regex for javascript [updated]
View the-beast-of-a-regex.js
/**
* i say updated because previously, the regex wouldn't
* like if you entered, 'mikey@rocks.email', which with
* recently added TLDs is a perfectly valid email address.
* So i looked up the maximum length for a TLD (which is
* 63 characters), and put it in here. Now it works pretty well.
* It even acceptes those GMail aliases (mikey+facebook@rocks.email)
*/
var EMAIL_REGEX = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.({2,63})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
@nkcmr
nkcmr / check-sw-reg.js
Last active Aug 29, 2015
push api zumba blog
View check-sw-reg.js
// the service worker api entry point is navigator.serviceWorker
navigator.serviceWorker
.getRegistration()
.then(function (registration) {
// 'registration' is an instance of ServiceWorkerRegistration, see here:
// http://www.w3.org/TR/service-workers/#service-worker-registration-interface
if (!registration) {
// there is no service worker installed!
} else {
// there is one installed, and it is either 'waiting'
@nkcmr
nkcmr / hsl2hex.php
Created Dec 11, 2012
HSL to HEX triplet algorithm
View hsl2hex.php
<?php
function HSL2HEX($h,$s,$l){
function hue2rgb($v1, $v2, $vH){
if($vH<0) $vH += 1;
if($vH>1) $vH -= 1;
if((6*$vH)<1) return $v1+($v2-$v1)*6*$vH;
if((2*$vH)<1) return $v2;
if((3*$vH)<2) return $v1+($v2-$v1)*((2/3)-$vH)*6;
return $v1;
@nkcmr
nkcmr / cssmq-js.js
Created Dec 11, 2012
css media query actions in javascript
View cssmq-js.js
var queries = [{
'match_this': 'only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5)',
'action': function () {
$('.post .entry-content img').each(function (index, element) {
$(this).attr('width', '100%');
$(this).removeAttr('height');
});
}
}, {
'match_this': 'only screen and (min-width : 321px)',
@nkcmr
nkcmr / window-watcher.js
Created Dec 11, 2012
this bit of code watches the conditions of the viewport and runs the appropriate query.
View window-watcher.js
var supportsOrientationChange = "onorientationchange" in window, //Check if device supports orientation change listening
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; //If so listen for orientation change, if not listen for resizing
window.addEventListener(orientationEvent, function() {
console.log('Orientation did Change!!');
for(i=0;i<queries.length;i++){ //Parse through queries
var mq = window.matchMedia(queries[i].match_this);
if(mq.matches){
queries[i].action();
break;
}
@nkcmr
nkcmr / cephei.php
Last active Apr 9, 2016
cephei - a tiny css pre-processor, written in php
View cephei.php
<?php
function cephei($selector, $properties) {
$output = sprintf("%s {\n", $selector);
$children = [];
foreach ($properties as $property => $value) {
if (is_array($value)) {
$children[$property] = $value;
} else {
$output .= sprintf(" %s: %s;\n", $property, $value);