Skip to content

Instantly share code, notes, and snippets.

View ceane's full-sized avatar
🎯
Reality

Ceane ceane

🎯
Reality
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceane
ceane / getElementCenter.js
Last active December 31, 2015 18:59
Collection of pure JS functions to get an element's center point
function getElementCenter(elem) {
var props = elem.getBoundingClientRect(),
x = 0,
y = 0;
//Calculating X
if (props.left > props.right)
x = (props.left - props.right)/2 + props.right;
else if (props.left < props.right)
@ceane
ceane / blur.scss
Last active July 9, 2020 13:19
SASS Blur Mixin
@mixin blur ($radius) {
-webkit-filter: blur($radius+px); /* Chrome, Safari */
-ms-filter: blur($radius+px); /* IE12? */
filter: url("data:image/svg+xml;utf8,<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"><filter id=\"blur\"><feGaussianBlur stdDeviation=\"#{$radius}\" /></filter></svg>#blur"); /* Firefox, Safari, Chrome*/
filter: progid:DXImageTransform.Microsoft.Blur(Strength=$radius); /* IE9 */
}
@ceane
ceane / color.md
Last active January 1, 2016 13:39
An interpretation of Clear's heat map color algorithm

#Clear's heatmap color algorithm

Barebones result

<ul id="list">
  <li>Milk</li>
  <li>Greens</li>
  <li>Flour</li>
 Eggs
@ceane
ceane / beizer.js
Last active January 4, 2016 09:39
Béizer curve calculations
//point as in [c1, c2]
function simpleDeCasteljau (point, t) {
return (1-t)*point[0] + t*point[1]
}
function pointInTimeOnBezier(startPoint, endPoint, time) {
return [
simpleDeCasteljau([startPoint[0], endPoint[0]], time),
@ceane
ceane / fastest_prefix.js
Created February 3, 2014 18:22
Fastest way to get a browser prefix. http://jsperf.com/fastest-prefix-check/2
function testForComputedMatches() {
var prefixes = 'webkit moz ms o'.split(' '), lt = prefixes.length, prefix = '', computed;
while (lt--) {
computed = window.getComputedStyle && window.getComputedStyle(document.body).getPropertyValue("-"+prefixes[lt]+"-transform");
if (!!computed) {
prefix = prefixes[lt];
break;
}
}

#Magical enums in ES6 My brain exploded with creativity today with this nefarious trick to make an enum by manipulating the syntax in ES6. The browser vendors will probably find this and block this from shipping, but it will still work with a transpiler (webpack + 6to5). To understand this you will need to know ES6 Proxies, ES6 modules, and Symbols.

your-code.js

import { blue, red, orange } from 'magic-enum';

var color = blue;

switch (color) {
@ceane
ceane / DrawListener.jsx
Last active August 29, 2015 14:15
Listen to mouse cursor draw, really useful for canvas drawing
import React from 'react';
// Before rendering run:
// React.initializeTouchEvents()
var Styles = {
WebKitUserSelect: 'none',
MozUserSelect: 'none',
MsUserSelect: 'none',
UserSelect: 'none',
@ceane
ceane / insertEvery.js
Last active September 11, 2015 17:48
Insert an item at a certain index in a recurring number of items inside of an array
/**
* Insert an item (d) at a certain index (b) in a
* recurring number (a) of items inside of an array (c)
*
* "For every 20 items in an array,
* insert this at the 12th index in that section"
*
* var myArray = Array.from({length: 80}, (v, k) => k);
* insertItemEvery(20, 12, myArray, "Hello index");
*