Skip to content

Instantly share code, notes, and snippets.

View nkcmr's full-sized avatar

nick comer nkcmr

View GitHub Profile
@nkcmr
nkcmr / spdy.js
Created February 11, 2014 17:36
replacing https with spdy
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 16:03
please-uphold-strict-net-neutrality.eml
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

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 February 4, 2015 21:52
$.fn.scrollIntoView
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 March 16, 2015 13:14
best working email regex for javascript [updated]
/**
* 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 August 29, 2015 14:20
push api zumba blog
// 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 / cssmq-js.js
Created December 11, 2012 14:53
css media query actions in javascript
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 December 11, 2012 14:54
this bit of code watches the conditions of the viewport and runs the appropriate query.
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 April 9, 2016 18:29
cephei - a tiny css pre-processor, written in 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);

Keybase proof

I hereby claim:

  • I am nkcmr on github.
  • I am nkcmr (https://keybase.io/nkcmr) on keybase.
  • I have a public key ASBCQWHPkNbeLwUL7moC-LL6vSSGgGzDRtkFuR6covWMXQo

To claim this, I am signing this object: