Skip to content

Instantly share code, notes, and snippets.

View xantiagoma's full-sized avatar

Santiago Montoya A. xantiagoma

View GitHub Profile
onEdit($event: Event) {
if( $event instanceof KeyboardEvent ) {
let key = ($event.keyCode || $event.charCode);
let maxLength = ($event.target as HTMLInputElement).maxLength;
let valueLength = ($event.target as HTMLInputElement).value.length;
if(maxLength === valueLength) {
let index = this.inputs.map(e => e.nativeElement)
.findIndex(e => e === $event.target);
let next = (index + 1) > (this.inputs.length - 1) ? (this.inputs.length - 1) : (index + 1);
(this.inputs[next].nativeElement as HTMLInputElement).focus();
public only($event: KeyboardEvent) {
console.log("press");
let regex: RegExp = new RegExp(/^[0-9a-zA-Z]{1,}$/g);
let specialKeys: Array<string> = ['Backspace', 'Tab', 'End', 'Home', 'ArrowRight','ArrowLeft'];
if (specialKeys.indexOf($event.key) !== -1) {
return;
} else {
if (regex.test($event.key)) {
return true;
} else {
@xantiagoma
xantiagoma / main.dart
Last active November 10, 2018 21:44
Hello World Flutter / Dart
import 'package:flutter/cupertino.dart'; // importa todas las funciones sin prefix
// import 'package:flutter/cupertino.dart' as cupertino; // go-style use cupertino.runApp(...
void main(){
runApp(
Center(
child: Text(
'Hello World',
), // Text
)
@xantiagoma
xantiagoma / ngGetWrongFormControls.js
Last active December 13, 2018 18:52
While debug copy & paste functions
// Select <gh-event> in Elements panel then in
// Console paste:
var eventForm = ng.probe($0).componentInstance.eventForm;
var FormArray = eventForm.constructor;
var FormGroup = eventForm.controls[0].constructor;
var findInvalidControlsRecursive = function findInvalidControlsRecursive(formToInvestigate) {
var invalidControls = [];
var recursiveFunc = function (form) {
Object.keys(form.controls).forEach(function (field) {
var control = form.get(field);
(async () => {
const { ajax: ajaxp, operators, from } = rxjs;
const { ajax } = ajaxp;
const { getJSON } = ajax;
const { map, flatMap, toArray } = operators;
const promise =
getJSON(
"https://pokeapi.co/api/v2/pokemon/"
)
.pipe(
@xantiagoma
xantiagoma / command.sh
Created May 2, 2018 14:24
Open mac app from unidentified developer
xattr -cr /Applications/<app>.app
@echo off
::
:: RefreshEnv.cmd
::
:: Batch file to read environment variables from registry and
:: set session variables to these values.
::
:: With this batch file, there should be no need to reload command
:: environment every time you want environment changes to propagate
/^((\+|\+\(|\(\+)?[0-9]+\)?)?([0-9]+| |-|\.)+(((extension|ext|ext\.|extension\.|ex|ex\.|e|e\.)? ?)[0-9]+)?$/igm
^((\+|\+\(|\(\+)?[0-9]+\)?)?([0-9]+| |-|\.)+(((extension|ext|ext\.|extension\.|ex|ex\.|e|e\.)? ?)[0-9]+)?$
$x48: 48em;
$x64: 64em;
$x75: 75em;
@mixin media($medias){
@each $media in $medias {
@if $media == xs {
@media only screen and (max-width: $x48) { @content; }
}
@else if $media == sm {
/**
* Returns value of specified URL parameter.
* @param {String} name Query parameter to return value of.
* @return {String} String of query parameter or null / 0.
*/
getUrlParameter = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#?]*)').exec(window.location.href);
if (results==null){ return undefined; }
else { return results[1] || 0; }
}