Skip to content

Instantly share code, notes, and snippets.

View edwinwebb's full-sized avatar

Edwin Webb edwinwebb

View GitHub Profile
@edwinwebb
edwinwebb / gist:5151220
Created March 13, 2013 11:21
Format MS to Time Stamp "MM:SS:XX" in Javascript
function formatSeconds(seconds, format) {
var ms = Math.floor((seconds*1000) % 1000);
var s = Math.floor(seconds%60);
var m = Math.floor((seconds*1000/(1000*60))%60);
var strFormat = format || "MM:SS:XX";
if(s < 10) s = "0" + s;
if(m < 10) m = "0" + m;
if(ms < 10) ms = "0" + ms;
@edwinwebb
edwinwebb / gist:5155504
Last active February 1, 2019 15:39
A simple less loop with comments and simple from, to syntax.
/* Define two variables as the loop limits */
@from : 0;
@to : 10;
/* Create a Parametric mixin and add a guard operation */
.loop(@index) when(@index =< @to) {
/* As the mixin is called CSS is outputted */
div:nth-child(@{index}) {
top: unit(@index * 100, px);
@edwinwebb
edwinwebb / gist:353d7a87194a357aeb77
Created November 12, 2014 10:48
Breakpoint indicator
body:before {
position: fixed;
content: "No Breakpoint";
background: white;
color:black;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
function colorText(str) {
var phase = 0;
var outputStr = new Array();
var args = new Array();
var center = 128;
var width = 127;
var frequency = Math.PI*2/str.length;
var red, green, blue, i;
function componentToHex(c) {
@edwinwebb
edwinwebb / throttle.js
Created April 30, 2015 09:40
Javascript Throttle Function
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time. Normally, the throttled function will run
// as much as it can, without ever going more than once per `wait` duration;
// but if you'd like to disable the execution on the leading edge, pass
// `{leading: false}`. To disable execution on the trailing edge, ditto.
// Replaced namespace and _.now function to function scope
// https://github.com/jashkenas/underscore/blob/master/underscore.js#L779
function throttle(func, wait, options) {
@edwinwebb
edwinwebb / pixi blendmodes
Created May 19, 2015 08:29
PIXI.js Blend Modes
{
"NORMAL": 0,
"ADD": 1,
"MULTIPLY": 2,
"SCREEN": 3,
"OVERLAY": 4,
"DARKEN": 5,
"LIGHTEN": 6,
"COLOR_DODGE": 7,
"COLOR_BURN": 8,
@edwinwebb
edwinwebb / test-one.txt
Created June 17, 2015 13:03
Spot the errors
/*
JavaScript Test
---------------
A small script to open a popup when clicking a link.
Once you click on the button, clinking on it again will close the popup.
*/
/* Task One - Improve this code
@edwinwebb
edwinwebb / test-two.js
Created June 17, 2015 13:14
JS Test Two
// The expensive animation is causing performance issues. Write the function 'yourFunction' that reduces calls to the animation.
function scrollHandler() {
var items = document.querySelectorAll('.list-item');
var i = 0;
var len = items.length;
for(; i < len; i++) {
// perform expensive animation
}
@edwinwebb
edwinwebb / bitcolor.js
Created September 5, 2016 11:54 — forked from lrvick/bitcolor.js
Javascript functions for doing fast binary/hex/RGB color conversions using bitwise operations.
// convert 0..255 R,G,B values to binary string
RGBToBin = function(r,g,b){
var bin = r << 16 | g << 8 | b;
return (function(h){
return new Array(25-h.length).join("0")+h
})(bin.toString(2))
}
// convert 0..255 R,G,B values to a hexidecimal color string
RGBToHex = function(r,g,b){
@edwinwebb
edwinwebb / RalCodes.json
Last active July 15, 2024 14:29
EU RAL Color Codes lookup table represented as JSON
{
"1000":{
"code":"1000",
"name":"Green beige",
"rgb":"205-186-136",
"hex":"#CDBA88"
},
"1001":{
"code":"1001",
"name":"Beige",