Skip to content

Instantly share code, notes, and snippets.

View TrevorJTClarke's full-sized avatar
🙈

Trevor Clarke TrevorJTClarke

🙈
View GitHub Profile
@TrevorJTClarke
TrevorJTClarke / .update()
Created March 8, 2013 02:28
Firebase .update() function in Node.js
function setThis () {
firebaseRef.child('users').child(user.name).set(user);
};
data.forEach(function (user) {
module.user(user.name, function(err, data){
firebaseRef.child('users').child(user.name).update(user, setThis());
});
});
@TrevorJTClarke
TrevorJTClarke / API_Router
Created May 31, 2014 07:17
API Route Module
function API (){
this._apiString = "";
//TODO: add this to check if we already have a param or not, then finish route
this.addQueryParam = function (){
// console.log(this._apiString.toString().search("\?"));
}
this.v = function (){
@TrevorJTClarke
TrevorJTClarke / MediaFormat
Last active July 24, 2023 08:25
MediaFormat - A regex system for finding the media ID for each type of popular social site. Can identify YouTube, Vimeo, Spotify, and Soundcloud.
/**
* MediaFormat
* format and return only needed pieces of media from their public sources
* Author: Trevor Clarke
*/
function MediaFormat (){
// http://www.youtube.com/embed/m5yCOSHeYn4
var ytRegEx = /^(?:https?:\/\/)?(?:i\.|www\.|img\.)?(?:youtu\.be\/|youtube\.com\/|ytimg\.com\/)(?:embed\/|v\/|vi\/|vi_webp\/|watch\?v=|watch\?.+&v=)((\w|-){11})(?:\S+)?$/;
// http://vimeo.com/3116167, https://player.vimeo.com/video/50489180, http://vimeo.com/channels/3116167, http://vimeo.com/channels/staffpicks/113544877
var vmRegEx = /https?:\/\/(?:vimeo\.com\/|player\.vimeo\.com\/)(?:video\/|(?:channels\/staffpicks\/|channels\/)|)((\w|-){7,9})/;
@TrevorJTClarke
TrevorJTClarke / state-list.js
Created November 12, 2014 17:43
Angular states and abbreviations list. Only using the 50 main states without outlying properties. Found the need to use on multiple projects, so gist for easy use!!
/**
* States
* A simple value store of states
*/
D.value("States", [{
"name": "Alabama",
"abbr": "AL"
},{
"name": "Alaska",
"abbr": "AK"
@TrevorJTClarke
TrevorJTClarke / Module Starter
Created March 31, 2015 23:10
A standard for building javascript modules -- pre-ES6
/**
* Module Starter
*/
var NS = "ModuleName";
// load the module into global
window[NS] = (function(){
/**
* Internal - encapsulates all logic
*
@TrevorJTClarke
TrevorJTClarke / chromeInstall.js
Created April 6, 2015 17:56
Chrome Inline Install Angular Directive
/**
* chromeInstall
* a directive for inline install of a chrome extension from a website using Angular
*
* Make sure that the head meta data contains:
* <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/CHROME_EXTENSION_ID">
*/
yourApp.directive('chromeInstall',
[function() {
return {
@TrevorJTClarke
TrevorJTClarke / Youtube Adapter
Created May 5, 2015 22:14
A quick youtube API adapter for playing nicely with other javascript modules.
/**
* Youtube quick module
*
* USE:
* var _yt = new youtube().init({
* element: "player",
* height: 350,
* width: 640,
* videoId: 'M7lc1UVf-VE'
* });
@TrevorJTClarke
TrevorJTClarke / The Best Directive Ever
Created May 5, 2015 22:39
An easter egg Angular directive. NBD.
/**
* tbde
* AKA "The Best Directive Ever"
*/
D.directive('tbde',
["$http","$rootScope", function ($http,$rootScope) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var randomGifUrl = "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=laugh";
@TrevorJTClarke
TrevorJTClarke / Dynamic Angular Array Filter
Created May 8, 2015 17:54
Easier setup for deep object based filtering on an array in angularjs. Use: ng-repeat="item in someArray | objectFilter:filterReqObject"
// I wanted to be able to simply change an object with key/search values, so that any array item keys that match also check for those search values
// The returned data, is only data that meets all requirements inside of the filterObject
//
// Example filterObject:{
// names: "Trevor",
// countries: "USA"
// }
// Example Array: [{
// title: "People in USA"
// names: ["Trevor", "Steve"]
@TrevorJTClarke
TrevorJTClarke / ES6: Arrows & Lexical This
Created May 13, 2015 19:44
A study into accessing "this" within the new lexical this, and arrow functions.
// Test array
var evens = [2,4,6,8,10]
// Example Expression
var nums = evens.map((v, i) => {
// here, "this" becomes undefined. There is no lexical parent to tie to.
console.log(this)
return v + i
})