Skip to content

Instantly share code, notes, and snippets.

View ldmarz's full-sized avatar
💯
Dandolo todo mientras me divierto

Lenin martinez ldmarz

💯
Dandolo todo mientras me divierto
View GitHub Profile
@ldmarz
ldmarz / and.js
Last active August 23, 2018 19:51
Example how use fuse operators
const query = 'old man && scalzi';
const result = fuseWithOperators(query, mockData);
// → [{"title": "Old Man's War", "author": {"firstName": "John", "lastName": "Scalzi"}}]
@ldmarz
ldmarz / app.js
Last active August 21, 2018 14:26
Example of lazy loaders on Angular
import { HomePage } from '../pages/home/home';
@NgModule({
declarations: [
MyApp,
HomePage
],
. . .
entryComponents: [
MyApp,
HomePage
import { Component, ViewChild } from '@angular/core';
import { SomeChildComponent } from './someChild/someChild.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild(SomeChildComponent) someChildComponent;
<some-parent-component>
<button (click)="callChildFunction()" > call child function </button>
<some-child-component></some-child-component>
</some-parent-component>
@ldmarz
ldmarz / compact.js
Created August 10, 2018 14:15
example of compact function from lodash
const someDirtyArray = [0, 1, false, 2, '', 3];
const cleanedArray = _.compact(someDirtyArray);
// cleanedArray => [1, 2, 3]
@ldmarz
ldmarz / Filter.js
Created August 10, 2018 14:10
Example of Filter from lodash library
var users = [
{ firstName: "Ldmarz", lastName: "martinez", age: 28, gender: "male" },
{ firstName: "Suli", lastName: "bern", age: 5, gender: "female" },
{ firstName: "Marianis", lastName: "Carrey", age: 54, gender: "female" },
{ firstName: "Jhon", lastName: "carret", age: 40, gender: "male" }
];
var femaleUsers = _.filter(users, function(user) {
return user.gender === 'female'
});
@ldmarz
ldmarz / uniq.js
Created August 10, 2018 14:03
Uniq example from lodash function
const someArray = [1, 1, 3]
const cleanArray = _.uniq(someArray);
// cleanArray === [1, 3]
@ldmarz
ldmarz / set.js
Created August 10, 2018 13:56
Set and Get lodash example
var someNiceObject = { hello: { someDeepKey: "hello" } };
_.set(someNiceObject, "hello.items[0]", "An item");
// here items was added safely
// someNiceObject === { hello: { someDeepKey: "hello", items: ["An item"] } }
//Here we can access to a not existing key getting a default value instead
var name = _.get(someNiceObject, "someNotExistingKey", "Ldmarz");
// name => Ldmarz
@ldmarz
ldmarz / find.js
Created August 10, 2018 13:43
Example of use find function from lodash
var users = [
{ firstName: "Ldmarz", lastName: "martinez", age: 28, gender: "male" },
{ firstName: "Suli", lastName: "bern", age: 5, gender: "female" },
{ firstName: "Marianis", lastName: "Carrey", age: 54, gender: "male" },
{ firstName: "Jhon", lastName: "carret", age: 40, gender: "female" }
];
var user = _.find(users, { name: "ldmarz", gender: "male" });
// { firstName: "Ldmarz", lastName: "martinez", age: 28, gender: "male" },
@ldmarz
ldmarz / ThrottleExample.js
Last active August 19, 2018 18:16
Example to Improve your javascript speed with throttle, example at: https://wp.me/pabITX-7j
// find elements
let i = 0;
function writeDOM() {
// Imagine some slow/hard function
$("#result").html(i++);
}
const $checkBox = $('#checkbox');
const throttleWriteDom = _.throttle(writeDOM, 1000);