Skip to content

Instantly share code, notes, and snippets.

View nire0510's full-sized avatar

Nir Elbaz nire0510

  • Holisto
View GitHub Profile
@nire0510
nire0510 / inline-style.helper.js
Created February 29, 2016 11:21
Ember helper: safe binding of inline style
import Ember from 'ember';
export function inlineStyle(params, hash) {
let strInnerStyle = '';
for (let key in hash) {
if (hash.hasOwnProperty(key)) {
hash[key] = (key === 'background-image') ? `url(${hash[key]})` : `${hash[key]}`;
strInnerStyle += `${key}: ${hash[key]}; `;
@nire0510
nire0510 / log-json.helper.js
Created February 29, 2016 11:21
Ember helper: pretty log of JSON object
import Ember from 'ember';
export function logJson(params/*, hash*/) {
console.log(params[0].toJSON());
}
export default Ember.Helper.helper(logJson);
@nire0510
nire0510 / math.helper.js
Created February 29, 2016 11:22
Ember helper: performs arithmetic operations
import Ember from 'ember';
export function math([numOperand1, strOperator, numOperand2]/*, hash*/) {
numOperand1 = parseFloat(numOperand1);
numOperand2 = parseFloat(numOperand2);
return {
'+': numOperand1 + numOperand2,
'-': numOperand1 - numOperand2,
'*': numOperand1 * numOperand2,
@nire0510
nire0510 / range.helper.js
Created February 29, 2016 11:23
Ember helper: generates range of numbers
import Ember from 'ember';
export function range(params/*, hash*/) {
var arrRange = [];
for (var i = params[0]; i <= params[1]; i++) {
arrRange.push(i);
}
return arrRange;
@nire0510
nire0510 / round.helper.hs
Created February 29, 2016 11:24
Ember helper: rounds number to specified floating point format
import Ember from 'ember';
export function roundNumber(params/*, hash*/) {
return parseInt(params[0]).toFixed(params[1] || 0);
}
export default Ember.Helper.helper(roundNumber);
@nire0510
nire0510 / file.css
Last active September 10, 2021 17:31
Ember.js Model Generator - Reverse engineer your JSON objects into Ember Data models
body {
background-color: #faf4f1;
}
form {
margin-top: 1rem;
}
dt {
color: #999;
@nire0510
nire0510 / generateHash.js
Created March 29, 2016 13:11
Generates has based on method parameters
function generateHash() {
let intHash = 0,
strChar,
intLength,
strInput = [...arguments].join('');
if (strInput.length === 0) {
return intHash;
}
@nire0510
nire0510 / index.js
Last active September 19, 2017 15:24
[Splice vs. Slice] #javascript
let a = [1, 2, 3, 4, 5, 6];
let b = [1, 2, 3, 4, 5, 6];
console.log('-- SLICE --');
console.log('- Returns values which were removed');
console.log('- Does not change the original array');
console.log(a.slice(0, 2));
console.log(a);
console.log();
@nire0510
nire0510 / get.js
Last active February 16, 2022 10:29
Naive implementation of lodash.get method
/**
* @property {object} object - The object to query
* @property {string} path - The path of the property to get
* @property {object} fallback - The default value to return if no value found in path
* @returns {*} Returns the resolved value (undefined / fallback value / value found).
*/
function get(object, path, fallback) {
const dot = path.indexOf('.');
if (object === undefined) {
@nire0510
nire0510 / distinct.js
Created April 4, 2018 12:17
Returns array which each of its elements appears only once
const arr = [1, 2, 2, 8, 5, 5, 3, 8, 3];
arr.sort().reduce((a, c) => {
if (a.includes(c)) {
return a;
}
a.push(c);
return a;
}, []);