Skip to content

Instantly share code, notes, and snippets.

View flipflop's full-sized avatar

Rozario Chivers flipflop

View GitHub Profile
@flipflop
flipflop / getClassNameByIndex
Created September 25, 2011 11:30
Get a class name from multiples
<div id="main" class="style1 style2 style3">
</div>
<script>
console.log(main.className.split(" ")[0]); // first className
console.log(main.className.split(" ")[1]); // second className
console.log(main.className.split(" ")[2]); // third className
@flipflop
flipflop / Javascript Buffered String (kinda)
Last active September 27, 2015 08:27
String Concatenation in JavaScript
// old concatenation (creates a new variable in memory for each +)
var stuckTogetherOld = "value1" + "value2" + "value3";
// Better:
// Front End Performance Tip for string concatenation or JS Templates
var stuckTogether = ["value1", "value2", "value3"].join("");
// Quicker to execute
var tmpl = ''.concat(
@flipflop
flipflop / gist:1240523
Created September 25, 2011 11:37
JavaScript Multi-line String Concatenation
// old way
var myOldString = "some really long text repeated" +
some really long text repeated" +
some really long text repeated";
// Potentially better for Performance and Memory usage
var myString = "some really long text repeated\n\
some really long text repeated\n\
@flipflop
flipflop / gist:1240536
Created September 25, 2011 11:58
JavaScript Closure to correct lost scope
<ul>
<li>item One</li>
<li>item Two</li>
<li>item Three</li>
</ul>
<script>
var listElements = document.getElementsByTagName("li");
@flipflop
flipflop / gist:1251044
Created September 29, 2011 15:47
JavaScript Module
/*
* Module pattern (public and private members within a namespace)
* Creates chassis.example namespace
* Note: ; before parenthesis is deliberate
*
* Below is an example of a flexible multi-part module that can be loaded
* in any order with loose augmentation.
*
*/
@flipflop
flipflop / gist:1263020
Last active September 27, 2015 11:28
Mobile Detection with Optional Zepto / jQuery include
<?php
$deviceClass = "";
if (ereg('iPhone',$_SERVER['HTTP_USER_AGENT']) || ereg('iPod',$_SERVER['HTTP_USER_AGENT'])) {
$deviceClass = "ui-iphone";
} else if (ereg('iPad',$_SERVER['HTTP_USER_AGENT'])) {
$deviceClass = "ui-ipad";
} else if (ereg('Android',$_SERVER['HTTP_USER_AGENT']) && ereg('Mobile Safari',$_SERVER['HTTP_USER_AGENT'])) {
$deviceClass = "ui-android";
};
?>
@flipflop
flipflop / gist:1263098
Created October 4, 2011 22:55
Non UI Blocking Script include
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
@flipflop
flipflop / gist:5943031
Created July 7, 2013 10:22
JavaScript Essentials
// 1. JS Namespacing
if (typeof mynamespace != "object") { var mynamespace = {}; }
mynamespace.component = function() {
// component safely nestled within a namespace
};
// 2. get a class name from multiples
$("#content").attr("class").split(" ")[0];
// 3. argument defaulting
@flipflop
flipflop / README-Template.md
Created February 6, 2018 21:24 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
import { connect } from 'ember-redux';
const stateToComputed = state => {
return {
number: state.number
};
};