Skip to content

Instantly share code, notes, and snippets.

View jefsnare's full-sized avatar

Jeffrey de Graaf jefsnare

View GitHub Profile
//DO NOT USE FRAMEWORKS
/**
* 1. Below discount rule should have dynamic data
* - Create a function to fill this dynamic data
* - Append to a HTML element with class .container
*/
var discountRule = 'Add two more 2 products and receive 5 euro discount!';
let roundUpValueByStep = (value, step) => {
return Math.ceil(value * (1 / step)) / (1 / step);
}
console.log(roundUpValueByStep(1.25, 0.5)); // 1.5
console.log(roundUpValueByStep(1.77, 0.5)); // 2
console.log(roundUpValueByStep(1, 0.5)); // 1
console.log(roundUpValueByStep(2.1, 0.25)); // 2.25
console.log(roundUpValueByStep(2.45, 0.25)); // 2.5
@jefsnare
jefsnare / pattern.js
Created October 30, 2013 12:57
JS pattern
// top-level namespace
var myApp = myApp || {};
// directly assign a nested namespace
myApp.library = {
foo:function(){
//...
}
};
@jefsnare
jefsnare / SassMeister-input.scss
Created January 29, 2015 13:54
Generated by SassMeister.com.
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// Susy (v2.1.3)
// ----
@import "susy";
@for $i from 1 through 50 {
.foo {
@jefsnare
jefsnare / jssprintf.js
Created November 14, 2014 08:31
JavaScript sprintf function
/**
* string.jssprintf function which acts like sprintf.
*
* Example
*
* 'Buy {0} get {1}'.jssprintf(5, 'one free');
* which results in;
* 'Buy 5 get one free'.
*/
(function () {
@jefsnare
jefsnare / prototype-pattern-example.js
Created November 4, 2014 09:12
Javascript prototype pattern example
/**
* -------------
* library.js
*
* Create Library function, register methods with prototype.
* More information about this pattern: http://tobyho.com/2010/11/22/javascript-constructors-and/
* -------------
**/
function Library () {
this.example = 'example data';
@jefsnare
jefsnare / gmapsapilatlngstring.js
Created September 16, 2014 07:25
Convert Google Maps API LatLng object to string/array
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': '1071 CX, Amsterdam, NL' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var result = results[0],
latlng = result.geometry.location.toString().replace(/\(|\)/g, '').split(', '));
console.log(latlng[0]); //lat
console.log(latlng[1]); //long
}
});
@jefsnare
jefsnare / SassMeister-input.scss
Created July 4, 2014 13:29
Generated by SassMeister.com.
// ----
// Sass (v3.3.9)
// Compass (v1.0.0.alpha.20)
// Bourbon (v4.0.2)
// Neat (v1.6.0)
// ----
@import "bourbon/bourbon", "neat/neat";
@for $i from 1 through 50 {
@jefsnare
jefsnare / SassMeister-input.scss
Created July 4, 2014 13:27
Generated by SassMeister.com.
// ----
// Sass (v3.3.9)
// Compass (v1.0.0.alpha.20)
// Singularity.gs (v1.2.1)
// ----
@import "singularitygs";
@include add-grid(12);
@include add-gutter(1/3);
@include add-gutter-style('split');
@jefsnare
jefsnare / SassMeister-input.scss
Created July 4, 2014 13:20
Generated by SassMeister.com.
// ----
// Sass (v3.3.9)
// Compass (v1.0.0.alpha.20)
// Susy (v2.1.2)
// ----
@import "susy";
@for $i from 1 through 50 {
.foo {