Skip to content

Instantly share code, notes, and snippets.

View banjeremy's full-sized avatar

Jeremy Jones banjeremy

  • pnw
  • 04:45 (UTC -07:00)
View GitHub Profile
@banjeremy
banjeremy / queryparams.js
Last active August 29, 2015 14:05
Here is a useful little function to grab the query string parameters from the window.location object.
function getQueryParams() {
var params = [];
var query = window.location.search;
query = query.slice(1, query.length);
var nv = query.split('&');
for (var i = 0; i < nv.length; i++) {
var q = nv[i].split('=');
params[q[0]] = q[1];
}
@banjeremy
banjeremy / thumbnail-directive.js
Last active August 29, 2015 14:13
Angular directive for thumbnail hover previews.
'use strict';
app.directive('thumbnail', function($interval){
return {
restrict: 'E',
scope: {
thumbs: '&thumbs',
speed: '&speed'
},
template: '<div class="thumbnail"><img ng-src="assets/images/thumbnails/{{thumb}}"/></div>',
@banjeremy
banjeremy / checkMediaSource.js
Created January 21, 2015 00:40
Detect if MediaSource API is available
(function(){
if (typeof MediaSource === typeof undefined){
alert('You must be on FireFox or some old IE bullshit');
} else {
alert('You are running a MediaSource API capable browser');
}
})();
@banjeremy
banjeremy / light
Created January 26, 2015 00:16
Firefox Light Sensor Events
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.darklight {
background-color: #000;
color: #fff;
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
@banjeremy
banjeremy / isDayAnOccurance.js
Last active May 24, 2016 17:54
checks if a given day is an occurance in a recurrence rule
export function isDayAnOccurance(day, recurrenceRule) {
const rule = RRule.fromString(recurrenceRule);
// Convert all dates into UTC before comparison
const today = moment(day).utc().startOf('day');
const nextOccurrence = moment(rule.after(today, true)).utc();
const match = moment(nextOccurrence).isSame(today, 'day');
return match;
}
@banjeremy
banjeremy / s3-stream.js
Created June 15, 2016 19:15
stream file to s3 using node.js
const S3 = require('aws-sdk').S3;
const fs = require('fs');
const body = fs.createReadStream('./my-file.txt');
const s3 = new S3();
s3.upload({
Bucket: 'my-bucket',
Key: 'my-directory/my-file.txt',
Body: body
@banjeremy
banjeremy / index.js
Created July 31, 2016 20:10
HMR for create-react-app
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
const rootEl = document.getElementById('root');
ReactDOM.render(
<App />,
rootEl
);
@banjeremy
banjeremy / getNestedProperty.js
Last active August 31, 2016 17:00
Retrieve deeply nested object properties by string
function getNestedProperty(obj, path) {
return path.split('.').reduce(function(prev, next) {
return prev ? prev[next] : undefined;
}, obj);
}
@banjeremy
banjeremy / authorize.sh
Created December 30, 2016 17:29
Linux no password ssh login
user=myuser
server=example.com
cat ~/.ssh/id_rsa.pub | ssh $user@$server "cat >> ~/.ssh/authorized_keys"