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 / javascript-stories.js
Last active September 1, 2017 17:00
Javascript stories
// The quick brown fox jumps over the lazy dog
var hasAttributes = function (animal, attributes) {
var matches = 0;
for (var i = 0; i < attributes.length; i += 1) {
if (animal.attributes.indexOf(attributes[i]) >= 0) {
matches += 1;
}
}
@JakeSidSmith
JakeSidSmith / ellipsized-filenames.css
Last active March 13, 2019 17:42
CSS - ellipsis filename but keep extension
/* HTML
<div class="file">
<div class="icon"></div>
<span class="filename">
<span class="name">
Filename<span class="extension">.ext</span>
</span>
</span>
@JakeSidSmith
JakeSidSmith / connection-monitor.py
Created March 6, 2015 11:34
Little python program for logging internet connection
import urllib2, time, socket
from datetime import datetime
previous_state = 'Monitoring started'
current_state = 'Monitoring started'
readable_time = None
time_now = None
disconnected_time = None
def start_monitoring():
@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"