Skip to content

Instantly share code, notes, and snippets.

View etoxin's full-sized avatar

Adam Lusted etoxin

View GitHub Profile
window.addEventListener("deviceorientation", function (e) {
var all = document.querySelectorAll('*');
for(var i = 0;i < all.length;i++) {
all[i].style.transform = 'rotateX('+e.alpha+'deg) rotateY('+e.gamma+'deg) rotateX('+e.beta+'deg)';
}
}, true);
@etoxin
etoxin / object.create.js
Last active May 14, 2018 21:00
Sharing between Objects
var Vehicle = {
describe: function () {
return `This ${this.type} is the ${this.make} ${this.model}.`;
}
}
var Car = Object.create(Vehicle, {
type: {value: 'Car', writable: true}
});
@etoxin
etoxin / helpers.js
Last active February 20, 2017 05:55
Handlebars KeystoneJS Debug helper
/**
* Handlebars KeystoneJS Debug helper
* @param optionalValue
*/
_helpers.debug = function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
@etoxin
etoxin / javascript.json
Last active January 25, 2017 00:11
Visual Studio Code User Snippets and Other Settings
{
"Print to console": {
"prefix": "l",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
},
"Simple function":{
@etoxin
etoxin / multilineTextWithEllipsis.scss
Created January 17, 2017 03:19
Multiline Text With Ellipsis
// font-size needs to be PX
// Line height needs to be em.
@mixin multilineTextWithEllipsis ($font-size, $line-height, $lines-to-show) {
display: block; /* Fallback for non-webkit */
display: -webkit-box;
max-width: 400px;
height: $font-size*$line-height*$lines-to-show; /* Fallback for non-webkit */
margin: 0 auto;
font-size: $font-size;
line-height: $line-height;
@etoxin
etoxin / lodash-conditional.js
Created December 2, 2016 02:23
Lodash Conditional
_.chain(123)
.thru(function(num) {
return _.every([ // or _.some for any item
_.isNumber(num),
_.anotherCheck(num),
_.anotherCheck(num)
]);
})
.value();
@etoxin
etoxin / jsonParse.js
Created November 30, 2016 23:05
JSON Parse
/**
* Lodash JSON Parse with error handling.
* The _.attempt prevents JSON.parse from throwing an application error. Instead, it return an Error object.
* @requires _
* @param str
* @returns {*}
*/
function lodashJSONParse (str) {
return _.attempt(JSON.parse.bind(null, str));
}
@etoxin
etoxin / scroll-bar.scss
Created November 10, 2016 03:40
Custom scrollbar
.whatever{
&::-webkit-scrollbar {
width: 10px;
}
/* Track */
&::-webkit-scrollbar-track,
&::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0,0,0,0);
border-radius: 10px;
}
@etoxin
etoxin / parseISOString.js
Created October 27, 2016 01:05
parseISOString.js
/**
* Parse an ISO string with or without an offset
* e.g. '2014-04-02T20:00:00-0600'
* '2014-04-02T20:00:00Z'
* '2014-02'
*
* Allows decimal seconds if supplied
* e.g. '2014-04-02T20:00:00.123-0600'
*
* If no offset is supplied (or it's Z), treat as UTC (per ECMA-262)
@etoxin
etoxin / JSON-Charts-Creator.js
Created October 10, 2016 01:07
JSON Charts Creator
// JSON Chart Data Maker
var points = [];
var days = 31;
var months = 12;
for (var x = 1; x < months; x++) {
for (var i = 1; i < days; i++) {
var day = i < 10 ? "0" + i : i;