Skip to content

Instantly share code, notes, and snippets.

😌

Iulia Maria Lungu iuliaL

😌
Block or report user

Report or block iuliaL

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@iuliaL
iuliaL / transformations.js
Last active Dec 26, 2017
Transform some piece of data with an array of functions + Array.reduce
View transformations.js
// transformations as an array of arrow functions
// example for transformations of an array, in this case [1,2,3]
const pipeline = [
// transformation functions here
array => { array.pop(); return array; },
array => array.reverse()
];
pipeline.reduce((xs, f) => f(xs), [1, 2, 3]);
@iuliaL
iuliaL / passPropsDownToRoute.js
Created Dec 11, 2017
React router v4: when I want to pass down props in a route to route children
View passPropsDownToRoute.js
const SynopticRoute = ({ scissor, ...rest })=> {
return (
<Route {...rest} render={(props)=>
<SynopticView scissor={scissor} {...props} />
} />
);
};
@iuliaL
iuliaL / key-del.ts
Last active Nov 9, 2017
Delete (nested) keys passed as any number of arguments from JSON object using recursion
View key-del.ts
"use strict";
import _ from 'lodash';
// works with
// just key name (i.e 'password', 'tenantName')
const recursiveCleaner = (object, keys) =>{
return Object.keys(object).reduce((objectSoFar, key) => {
if (object[key] && typeof object[key] === 'object') {
objectSoFar[key] = recursiveCleaner(object[key], keys);
@iuliaL
iuliaL / key-del.js
Last active Nov 9, 2017
Delete a (nested) key from JSON object
View key-del.js
// works with just one key to delete (for now) by proving
// complete path (i.e 'rows.0.panels.0.password') or
// just key name (i.e 'password')
import '_' from 'lodash';
const DOT_SEPARATOR = ".";
function checkPath(arr, object){
arr.forEach((chunk, index, array)=> {
@iuliaL
iuliaL / formatTelephoneNumber.js
Created Oct 24, 2017
Regex - format a telefhone number
View formatTelephoneNumber.js
string = "0727937613";
string.replace(/^(\d{4})(\d{3})(\d{3})$/, "($1) $2-$3");
=> "(0727) 937-613"
@iuliaL
iuliaL / revertNames.js
Created Oct 24, 2017
REGEX: Using Replace with Captured Groups
View revertNames.js
let string = "Joaquin Smith";
string.replace(/^(\w+) (\w+)$/, '$2 $1')
=> "Smith Joaquin"
@iuliaL
iuliaL / gist:25d83f7a9163ed3d434629cc8ff774e1
Last active Oct 4, 2017
Miimetiq developer manual questions
View gist:25d83f7a9163ed3d434629cc8ff774e1

1. Did not understand type : dict

I searched and seems to be a Python dictionary so I guess it's a key - val pairs list? I understand the document nesting in a noSQL (Mongo) db. It it just the type : dict that i've never seen before

    "engine": {
        // A subdocument inside the main document
        "type": "dict",
        ....
         }
@iuliaL
iuliaL / isNotMobile.js
Last active Oct 24, 2017
check if platform is mobile
View isNotMobile.js
function _isNotMobile (){
let check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|k
@iuliaL
iuliaL / integerPower.js
Last active Oct 24, 2017
an implementation of positive or negative integer powers
View integerPower.js
function pow(base,power) {
if ( power < 0 ) {
return ( 1 / pow( base, -(power)) );
} else if (power == 0){
return 1;
} else {
return base * pow(base, power - 1);
}
}
@iuliaL
iuliaL / removeItemFromArray.js
Last active Jun 29, 2017
remove item from array in a declarative way, avoiding array mutations
View removeItemFromArray.js
/*
remove item from array in a declarative way,
avoiding array mutations
Instead of splicing
*/
// 1. use Array.filter
const removeItem = (list,index) => list.filter((item,i) => index !== i)
You can’t perform that action at this time.