Skip to content

Instantly share code, notes, and snippets.

@ccnixon
ccnixon / sublime_text_2_perfect_key_bindings
Created August 3, 2016 22:32 — forked from koulmomo/sublime_text_2_perfect_key_bindings
Perfect Sublime Text 2 Key Bindings. Tab to skip out of brackets, braces, parentheses, and quotes/quotations but still be able to indent
[
// Move out of common paired characters () and [] with `Tab`
{
"keys": ["tab"],
"command": "move",
"args": {"by": "characters", "forward": true},
"context": [
{"key": "auto_complete_visible", "operand": false},
// Check if next char matches (followed by anything)
{ "key": "following_text", "operator": "regex_match", "operand": "(:?`|\\)|\\]|\\}).*", "match_all": true },
@ccnixon
ccnixon / utmParser.js
Created July 27, 2016 18:26
Parse and store UTM params from query string with minimal dependencies
var utmParser = function() {
var query = window.location.search
function decode(value) {
try {
return decodeURIComponent(value);
} catch (e) {
debug('error `decode(%o)` - %o', value, e)
}
}
<iframe id="verse-media-destination-frame" src="https://VERSE-MEDIA-PLAYER-IFRAME-URL"></iframe>
<script>
//Function to read value of a cookie
function readCookie(name) {
var cookiename = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
@ccnixon
ccnixon / iframeSnippet.html
Created June 20, 2016 21:27 — forked from sperand-io/iframeSnippet.html
Using Segment via iFrame Communication
<script>
/**
* Provides a fake analytics object that sends all calls to the parent window for processing
*/
var analytics = (function() {
var eventQueue = [];
// Send the events to the frame if it's ready.
function flush(method, args) {
while (eventQueue.length) {
@ccnixon
ccnixon / index.html
Created April 7, 2016 14:26
Simple Event Timeline (React)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Datanyze Challenge</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<style>
@ccnixon
ccnixon / CorsRequest.js
Created February 17, 2016 19:39 — forked from subnetmarco/CorsRequest.js
Sample code for executing an AJAX request using jQuery.
$.ajax({
url: 'MASHAPE-URL', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'POST', // The HTTP Method
data: {}, // Additional parameters here
dataType: 'json',
success: function(data) { alert(JSON.stringify(data)); },
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "YOUR-MASHAPE-KEY"); // Enter here your Mashape key
}
@ccnixon
ccnixon / chunk.js
Created February 17, 2016 18:22
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
function chunk(arr, size) {
var results = [];
while(arr.length){
results.push(arr.splice(0,size));
}
return results;
}
chunk(["a", "b", "c", "d"], 2);
@ccnixon
ccnixon / truncateStr.js
Created February 9, 2016 20:41
Truncate a string: Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a "..." ending.
function truncate(str, num) {
// Clear out that junk in your trunk
return num >= str.length? str: str.slice(0, num - (num <= 3 ? 0 : 3)) + '...';
}
truncate("A-tisket a-tasket A green and yellow basket", 11);
@ccnixon
ccnixon / end.js
Created February 9, 2016 20:21
Confirm the Ending: Check if a string (first argument) ends with the given target string (second argument).
function end(str, target) {
return str.substring(str.length - target.length) === target;
}
end("Bastian", "n");
@ccnixon
ccnixon / findLongestWord.js
Created February 9, 2016 19:48
Find the Longest Word in a String: Return the length of the longest word in the provided sentence.
function findLongestWord(str) {
str = str.split(' ');
return str.reduce(function(a,b ){ return a.length > b.length ? a : b;}).length
}
findLongestWord("The quick brown fox jumped over the lazy dog");