Skip to content

Instantly share code, notes, and snippets.

View luisfarfan's full-sized avatar

Luis Eduardo Farfan Melgar luisfarfan

  • Peru, Lima
View GitHub Profile
var arr = ['Sacha', 'Og', 'Haru'];
arr[Symbol.iterator] = function *() {
var i = this.length - 1;
while (i >= 0) {
yield this[i];
i--;
}
}
for (var value of arr) {
@luisfarfan
luisfarfan / only-number.directive.md
Created February 8, 2019 16:48 — forked from ahmeti/only-number.directive.md
Angular 5 - Only Number Input, Only Number Decimal

Angular 5 - Only Number Input, Only Number Decimal

Allow Only Numbers [0-9]

<input numeric numericType="number" type="text">

Allow Numbers & Decimals [0-9] [also only one dot]

<input numeric numericType="decimal" type="text">
@luisfarfan
luisfarfan / HttpStatusCode.ts
Created January 23, 2019 06:29 — forked from scokmen/HttpStatusCode.ts
Typescript Http Status Codes Enum
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
@luisfarfan
luisfarfan / async-foreach.js
Created December 31, 2018 10:05 — forked from atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
var talk = talky;
var cat = {
speak: talk,
sound: 'miau'
}
var dog = {
speak: cat.speak,
sound: 'wof'
}
function talky() {
@luisfarfan
luisfarfan / prueba_typescript.ts
Created July 5, 2018 20:26
Conversión de javascript a Typescript
// Uso de Let y Const
// var nombre = "César Tapia";
// var edad = 32;
// var PERSONAJE = {
// nombre: nombre,
// edad: edad
// };
// Resolución 1:
/** envolvi esta resolución para que no cause conflictos con la Resolución 2 */
/**
* El siguiente ejercicio es crear una función que implemente la siguiente lógica.
* const a = getIn(obj, path, defaultValue)
* Ejemplo:
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
* getIn(object, 'a.b.c', 'default');
* // => 'default'
* var object2 = {a: { b: { c: 3 } } };
* getIn(object2, 'a.b.c', 5);
* // => 3
@luisfarfan
luisfarfan / lpstat_email.py
Created February 28, 2018 15:10 — forked from jphenow/lpstat_email.py
Quick little script for Linux admins. Run periodically and setup to email someone with a description of printers that may happen to go down. Currently only written to run lpstat on localhost, so must be printers avilable to the localhost.
#! /usr/bin/python
"""
Description: Will run an lpstat -p and send an email to jtrutwin notifying him of a disabled printer, if there is one, so that he can take action.
TODO:
1) Add parameter to override the recipient of the email
2) Add functionality for only sending email when a printer hasn't been found to be disabled today - ie. email sent at 5am shouldn't be sent again if only that same printer is disabled as of 8am, should only send another email if another printer has been disabled or if the original printer has been disabled, enabled and re-disabled.
"""
import commands
@luisfarfan
luisfarfan / API.md
Created July 12, 2017 19:31 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method: