Skip to content

Instantly share code, notes, and snippets.

View JakeSidSmith's full-sized avatar
💭
Being awesome 😎

Jake 'Sid' Smith JakeSidSmith

💭
Being awesome 😎
View GitHub Profile
@JakeSidSmith
JakeSidSmith / cover-element.js
Last active August 29, 2015 14:01
JQuery to make images cover their containing elements (cropped)
$(document).ready(function () {
// Find thumbnail containers
$('.thumbContainer').each(function () {
// Get current thumbnail container
var thumb = $(this);
// Get current thumbnail image
var img = thumb.children('img');
// Calculate image ratio
var ratio = img.innerWidth() / img.innerHeight();
var newW, newH;
@JakeSidSmith
JakeSidSmith / o_0.js
Last active August 29, 2015 14:01
o_0.js - Useless functions
var o_0 = {};
o_0.isOdd = function(thing, normal) {
return thing !== normal;
};
o_0.isANinja = function (element) {
return element.style.visibility === 'hidden';
};
@JakeSidSmith
JakeSidSmith / promise-like-ifs.js
Last active August 29, 2015 14:17
Messing around with promise-like syntax for if statements
var ifTrue = function (value) {
var resolved, stored;
var result = value;
return {
then: function (fn) {
if (value) {
if (typeof fn === 'function') {
fn();
} else {
@JakeSidSmith
JakeSidSmith / ternary-fn.js
Created March 15, 2015 05:13
Messing around with potentially nicer ways to write ternaries
var ternary = function (bool, success, fail) {
return bool ? success : fail;
};
var message = ternary(true, 'Hello', ternary(true, 'Werld', 'World'));
console.log(message);
@JakeSidSmith
JakeSidSmith / (╯°□°)╯︵ ┻━┻.js
Last active August 29, 2015 14:22
Flip a table from columns to rows & vice versa
/*
# Flip a table from columns to rows & vice versa e.g.
var table = [
['Date', 'Jan', 'Feb', 'Mar', 'Apr', 'May'],
['Data 1', 45, 63, 68, 44, 86],
['Data 2', 57, 74, 15, 44, 53],
['Data 3', 47, 37, 76, 64, 62]
];
@JakeSidSmith
JakeSidSmith / is-javascript-insane.js
Created June 1, 2015 17:03
Simple function to check if the language you are using is insane. :P
var isJavascriptInsane = function () {
return typeof ({} + []) === 'string';
};
@JakeSidSmith
JakeSidSmith / .eslintrc
Last active August 29, 2015 14:27
ES Lint Config
/*
* Also consider rules from this
* https://github.com/yannickcr/eslint-plugin-react
*/
{
"rules": {
"strict": [
2,
"function"
@JakeSidSmith
JakeSidSmith / index.js
Last active August 29, 2015 14:28
HipChat Emoticon Bookmarklet (Work in progress)
/* global $ */
/*
* JSFiddle: http://jsfiddle.net/dswf3mh6/
*/
(function () {
'use strict';
$.get('https://www.hipchat.com/emoticons', function (response) {
@JakeSidSmith
JakeSidSmith / ternary.js
Created October 18, 2015 05:00
Alernative syntax for nested ternaries
var Ternary = function (condition, result) {
var resolved;
if (condition) {
resolved = result;
}
var ifFn = function (condition, result) {
if (resolved) {
return new Ternary(true, resolved);
@JakeSidSmith
JakeSidSmith / test.js
Created October 18, 2015 05:22
Wrapper for testing nested smart redux components with jest
let preprops = {
foo: 'bar'
};
spyOn(Redux, 'connect').andReturn(function (UnconnectedComponent) {
return class Prepropulator extends React.Component {
render() {
let props = Object.assign({}, this.props, preprops);
return (