Skip to content

Instantly share code, notes, and snippets.

View AlejandroPerezMartin's full-sized avatar
🇮🇨

Alejandro Pérez Martín AlejandroPerezMartin

🇮🇨
View GitHub Profile
@AlejandroPerezMartin
AlejandroPerezMartin / dropdown.js
Last active February 8, 2022 08:31
Accessible dropdown
/**
* Dropdown Component
*
* Add 'data-dropdown' and 'aria-controls' with the element id to toggle
*/
const Dropdown = () => {
const dropdowns = document.querySelectorAll('[data-dropdown]');
// If there's no wrapper, bail.
const isRequired = () => { throw new Error('param is required'); };
function filterEvil(array, evil = isRequired()) {
return array.filter(item => item !== evil);
}
@AlejandroPerezMartin
AlejandroPerezMartin / button-focus-remover.ts
Last active April 11, 2023 15:18
Angular 9+ Directive to remove focus after clicking the specified selector/s
import { Directive, HostListener, ElementRef } from '@angular/core';
/**
* This directive removes focus from the selectors after clicking on them
*/
@Directive({
selector: 'button, a' // your selectors here!
})
export class FocusRemover {
constructor(private elRef: ElementRef) {}
@AlejandroPerezMartin
AlejandroPerezMartin / promises.js
Created April 8, 2016 07:59
JavaScript Promises test
window.onload = function() {
init();
otherFn();
}
function init() {
var myPromise = new Promise(function(resolve, reject){
setTimeout(function() {
resolve("Promise called!");
}, 1000);
@AlejandroPerezMartin
AlejandroPerezMartin / shell-notes
Created March 9, 2015 13:05
LFS101x.2 Introduction to Linux - Notes
#!/bin/bash
# Declaring functions
function display() {
echo "Hello" $1 "!"
}
# ./my_script.sh param1 param2
# $0 (script name)
# $1 .. $n (nth parameter)
@AlejandroPerezMartin
AlejandroPerezMartin / unix-commands
Last active August 29, 2015 14:16
Unix terminal commands
#!/bin/bash
! # Start a history substitution
!$ # Refer to the last argument in a line
!string # Refer to the most recent command starting with string
# example
echo !$
# Network
#!/bin/bash
# Calculate parameters
cvt 1920 1080
# Create new mode
xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
# Add new mode to screen
xrandr --addmode VGA-0 "1920x1080_60.00"