Skip to content

Instantly share code, notes, and snippets.

View mig82's full-sized avatar
🏠
Working from home

Miguelángel Fernández mig82

🏠
Working from home
View GitHub Profile
@mig82
mig82 / add_to_bashrc
Last active June 28, 2022 18:04
findbyport and killbyport
findbyport() {
# lsof -i | grep ":$@" | awk '{print "Program: " $1 "\t" "PID: "$2 "\t" "User: " $3 "\t" "Address: "$9 "\t" "Action: " $10 }'
lsof -i ":$@" | grep ":$@" | awk '{print $2}'
}
killbyport() {
kill $(findbyport $@)
}
portsinuse() {
@mig82
mig82 / keboard_sleep.sh
Created May 13, 2022 09:40
Make your main keyboard sleep for a while, for example if you're placing a different one on top, or your kid is banging on it.
keyboard_sleep(){
# xinput -list
xinput --disable "AT Translated Set 2 keyboard"
sleep 3600 ; xinput --enable "AT Translated Set 2 keyboard"
}
keyboard_awake(){
# xinput -list
xinput --enable "AT Translated Set 2 keyboard"
}
@mig82
mig82 / portfinders.zsh
Created December 15, 2021 18:39 — forked from evanscottgray/portfinders.zsh
put this in your $shellrc and enjoy
# Find ALL the port users. _o/
findbyport() {
lsof -nP | grep ":$@" | awk '{print "Program: " $1 "\n" "PID: "$2 "\n" "User: " $3 "\n" "Address: "$9 "\n" "Action: " $10}'
}
portsinuse() {
lsof -nP | grep "IPv" | while read line; do echo $line | awk '{print "Program: " $1 "\n" "PID: "$2 "\n" "User: " $3 "\n" "Address: "$9 "\n" "Action: " $10}'; echo; done;
}
@mig82
mig82 / require_config.js
Created August 27, 2021 08:11
RequireJS module from a remote or CDN location
// We do this to avoid cluttering the project with 3rd party JS.
// It also avoids loading all the 3rd party JS at app launch.
require.config({
paths: {
"lodash": "https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min",
"moment": "https://momentjs.com/downloads/moment-with-locales.min"
},
waitSeconds: 10
});
@mig82
mig82 / def_getters_setters.js
Last active June 9, 2021 08:30
defineSetters and defineGetters
"use strict"
/*exported defineGetters*/
/**
* Applies a function as the getter function for all the custom properties
* of a component named in an array.
* This is useful to avoid repeating yourself when the getter for two or more
* custom properties is the same —e.g.
* <pre><code>
@mig82
mig82 / cloc-for-vis
Created March 17, 2021 15:28
Use CLOC to count lines of code in a Visualizer project.
echo jssrc > cloc_exclude_list
echo models >> cloc_exclude_list
echo studioactions >> cloc_exclude_list
echo modules/kony_sdk.js >> cloc_exclude_list
echo modules/require/moment.min.js >> cloc_exclude_list
cloc . \
--exclude-list-file=cloc_exclude_list \
--ignore-whitespace \
--include-ext=js \
@mig82
mig82 / sparse-checkout-visualizer-makefile
Last active April 26, 2021 16:01
A makefile that applies Git sparse checkout on a Visualizer project.
# Pass in the path to the file that contains the path patterns for the app
# groups you want to check out —e.g.
#
# make checkout patterns=path/to/fooModule
#
# Where fooModule is a flat file with glob patterns like the ones defined
# at: https://www.git-scm.com/docs/git-sparse-checkout#_full_pattern_set
#
# You should ideally keep one of these pattern files per app group, and model
# your app groups after stand-alone modules, with matching names for forms
@mig82
mig82 / .bash_profile
Created December 2, 2020 10:05
Show current folder and git branch in prompt
alias gitify_my_prompt="PS1='\[\033[96m\]\W\[\033[95m\] [\$(git symbolic-ref --short HEAD 2>/dev/null)]\[\033[00m\]\$' "
gitify_my_prompt
@mig82
mig82 / FooComponentController.js
Last active February 1, 2021 16:58
A sample controller for a Visualizer component.
//Break component code into separate modules and load them as dependencies.
define(["./animateIn, ./validateSomething"], function(animateIn, validateSomething) {
// Static constant. Shared across instances of this component. Can't be changed.
const SOME_CONSTANT = 3.14159;
// Static variable. Shared across instances of this component. Can be changed by any instance.
var count = 0;
// Static function. Shared by all instances of this component. Can't be changed.
@mig82
mig82 / sampleFormController.js
Last active September 10, 2021 16:46
A sample form controller for Vis Quantum projects
define(["util/doBar", "util/getQux"], function(doBar, getQux){
const PI = 3.1416
let count = 0
function doFoo(){ //This is a static function.
//TODO
}
return{