Skip to content

Instantly share code, notes, and snippets.

View serweb-labs's full-sized avatar

Luciano Rodríguez serweb-labs

View GitHub Profile
@nestoru
nestoru / Solution for mysql Warning: Using a password on the command line interface can be insecure
Last active October 23, 2021 21:20
Solution for mysql Warning: Using a password on the command line interface can be insecure
# Let us consider the following typical mysql backup script:
mysqldump --routines --no-data -h $mysqlHost -P $mysqlPort -u $mysqlUser -p$mysqlPassword $database
# It succeeds but stderr will get:
# Warning: Using a password on the command line interface can be insecure.
# You can fix this with the below hack:
credentialsFile=/mysql-credentials.cnf
echo "[client]" > $credentialsFile
echo "user=$mysqlUser" >> $credentialsFile
echo "password=$mysqlPassword" >> $credentialsFile
@gaearon
gaearon / slim-redux.js
Last active December 3, 2024 06:34
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@yowu
yowu / HttpProxy.go
Last active March 26, 2025 05:23
A simple HTTP proxy by Golang
package main
import (
"flag"
"io"
"log"
"net"
"net/http"
"strings"
)
@modernserf
modernserf / protocols.js.md
Last active March 18, 2024 12:29
Protocols/Interfaces in JavaScript with Symbols and bind syntax

Interfaces and protocols

ES2015, The newest iteration of JavaScript, introduces a ton of new features, types, and syntactic sugar. Those have all been explored pretty thoroughly, but the one that has the greatest implications for JavaScript are iterators; not the construct in itself but the use of the Iterator protocol.

Iterators are made possible by two new features: symbols and generators. Iterators are not necessarily a feature on their own, but rather a set of conventions around symbols and generators:

Given that JavaScript does not have interfaces, Iterable is more of a convention:

Source: A value is considered iterable if it has a method whose key is the symbol Symbol.iterator that returns a so-called iterator. The iterator is an object that returns values via its method next(). We say: it enumerates items, one per method call.

@harlow
harlow / golang_job_queue.md
Last active March 29, 2025 04:55
Job queues in Golang
@SebCorbin
SebCorbin / block.tpl.twig
Last active July 8, 2021 09:50
Drupal Bootstrap theme main templates converted to Twig
<section id="{{ block_html_id }}" class="{{ classes }} clearfix"{{ attributes }}>
{{ title_prefix }}
{% if title %}
<h2{{ title_attributes }}>{{ title }}</h2>
{% endif %}
{{ title_suffix }}
{{ content }}
</section>
@cesarmiquel
cesarmiquel / entity-metdata-wrapper-examples.md
Last active September 15, 2017 20:16
Entity Metadata Wrapper API examples

Entidades en Drupal 7

En Drupal 7 se 'mergearon' los usuarios, nodos y taxonomías en una entidad. Las entidades pueden tener campos adicionales a los que ya tenían. Adicionalmente, cada campo puede estar traducido y, por lo tanto, tener distintos valores dependiendo del idioma. En general es mejor acceder a los valores de los campos via APIs en lugar de acceder directamente al campo. Listamos algunas de las funciones más útiles y recomendadas para utilizar:

  • entity_load() - permite cargar una entidad. Los tipos de las entidades pueden ser 'node', 'user', etc. Ver: entity_load()
  • field_get_items() - devuelve, dada una entidad y el nombre de un campo la lista de valores que contiene el campo. Ver: field_get_values()
  • field_view_value() - devuelve un array rendereable con el valor. Para obtener HTML hacer drupal_rend
@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@wmayner
wmayner / OrbitControls.js
Last active January 25, 2018 14:48
Fork of three.js Orbit Controls that allows binding its event handlers to arbitrary elements, rather than just the given `domElement`. Useful when adding sibling DOM elements to the canvas, e.g. labels for objects.
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
/*global THREE, console */
// This set of controls performs orbiting, dollying (zooming), and panning. It maintains

The Tao of Unix

  1. Rule of Modularity: Write simple parts connected by clean interfaces.
  2. Rule of Clarity: Clarity is better than cleverness.
  3. Rule of Composition: Design programs to be connected to other programs.
  4. Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
  5. Rule of Simplicity: Design for simplicity; add complexity only where you must.
  6. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
  7. Rule of Transparency: Design for visibility to make inspection and debugging easier.