Skip to content

Instantly share code, notes, and snippets.

View antonioaguilar's full-sized avatar

Antonio Aguilar antonioaguilar

View GitHub Profile
@antonioaguilar
antonioaguilar / does program exist in bash
Created May 12, 2016 14:36
Check if a program exists in bash
http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
Yes; avoid which. Not only is it an external process you're launching for doing very little (meaning builtins like hash, type or command are way cheaper), you can also rely on the builtins to actually do what you want, while the effects of external commands can easily vary from system to system.
Why care?
Many operating systems have a which that doesn't even set an exit status, meaning the if which foo won't even work there and will always report that foo exists, even if it doesn't (note that some POSIX shells appear to do this for hash too).
Many operating systems make which do custom and evil stuff like change the output or even hook into the package manager.
So, don't use which. Instead use one of these:
@antonioaguilar
antonioaguilar / angular-bootstrap-with-config.js
Created October 1, 2016 11:01 — forked from DioNNiS/angular-bootstrap-with-config.js
Initiate angular application with server config
(function(angular) {
'use strict';
fetchConfig().then(bootstrapApplication);
function fetchConfig() {
var injector = angular.injector(['ng']);
var $http = injector.get('$http');
return $http.get('config.json').then(function(response) {
@antonioaguilar
antonioaguilar / setup.sh
Created October 14, 2016 00:35 — forked from lazypower/setup.sh
Setup headless chromium driver for selenium (vagrant flavor, but works with any ubuntu variant)
#!/bin/sh
set -e
if [ -e /.installed ]; then
echo 'Already installed.'
else
echo ''
echo 'INSTALLING'
echo '----------'
@antonioaguilar
antonioaguilar / pubsub-simple.js
Created December 10, 2016 02:00 — forked from fatihacet/pubsub-simple.js
Simple PubSub implementation with JavaScript - taken from Addy Osmani's design patterns book -
var pubsub = {};
(function(q) {
var topics = {}, subUid = -1;
q.subscribe = function(topic, func) {
if (!topics[topic]) {
topics[topic] = [];
}
var token = (++subUid).toString();
topics[topic].push({
token: token,
@antonioaguilar
antonioaguilar / Middleware.js
Created December 29, 2016 11:35 — forked from darrenscerri/Middleware.js
A very minimal Javascript (ES5 & ES6) Middleware Pattern Implementation
var Middleware = function() {};
Middleware.prototype.use = function(fn) {
var self = this;
this.go = (function(stack) {
return function(next) {
stack.call(self, function() {
fn.call(self, next.bind(self));
});
@antonioaguilar
antonioaguilar / flow.js
Created April 10, 2017 21:21 — forked from stevenkaspar/flow.js
VexFlow SVG Javascript Animation
var Note = function(options){
console.log(window);
this.StaveNote = new Vex.Flow.StaveNote(options);
this.removed = false;
/**
* moves the note right from its ORIGINAL position by x pixels
* (sets the trasform: translate(x) value to x)
*/
this.setOffsetX = (x) => {
if(this.removed){
@antonioaguilar
antonioaguilar / js-observables-binding.md
Created June 28, 2017 02:24 — forked from austinhyde/js-observables-binding.md
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

@antonioaguilar
antonioaguilar / sysctl.conf
Created August 19, 2017 22:11 — forked from techgaun/sysctl.conf
Sysctl configuration for high performance
### KERNEL TUNING ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
@antonioaguilar
antonioaguilar / gist:4acdfd129cc36cbc06992ebfb7b63a4a
Created August 19, 2017 22:11 — forked from jedi4ever/gist:903751
Tuning stuff for Ubuntu hosts
# /etc/security/limits.conf
* soft nofile 999999
* hard nofile 999999
root soft nofile 999999
root hard nofile 999999
===========================================================
# /etc/sysctl.conf
# sysctl for maximum tuning
@antonioaguilar
antonioaguilar / nginx.conf
Created January 14, 2018 18:10 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048