Skip to content

Instantly share code, notes, and snippets.

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

Aníbal Rodríguez Carrasco anibal21

🏠
Working from home
  • Santiago,Chile.
View GitHub Profile
@anibal21
anibal21 / jdfClasses.js
Created May 24, 2022 16:57
Javascript - The definitive guide - David Flanagan - Classes Chapter
/**
* Theory:
-Classes use prototype-based inheritance
*/
/**
* Relevant Examples
*/
@anibal21
anibal21 / jdfArrays.js
Last active May 23, 2022 00:04
Javascript - The definitive guide - David Flanagan - Arrays Chapter
/**
* Theory:
-Arrays in JavaScript are an ordered collection of values
-Its elements are untyped, an array can contain different types of data
-Arrays are 32-bit indexed so its index can be from 0-4294967294 (2^32 - 2)
and its elements can go from 0 to 4.294.967.295
*/
/**
* Relevant Examples
@anibal21
anibal21 / JS_generator_functions.js
Created April 20, 2022 19:39
Example of generator functions in JS.
const handsomeArray = [
"Option1",
"Option2",
"Option3",
"Option4",
"Option5",
"Option6"
]
function * generatorFunction(array) { // Line 1
/**
* When we do a freeze to an object, we only can read their items.
*/
const obj = {
prop: 42
};
Object.freeze(obj);
obj.prop = 55;
/**
* Explanation with an interview example from real life
* Call invokes the function and allows you to pass in arguments one by one.
* Apply invokes the function and allows you to pass in arguments as an array.
* Bind returns a new function, allowing you to pass in a this array and any number of arguments.
**/
// Call - Example
const callSomeone = (name, callback) => {
const innerMessage= {
@anibal21
anibal21 / JS_interpreter_1.js
Last active April 20, 2022 04:58
JavaScript interpreter Problems
// This validation is correct, because is not undefined neither zero
if(42){
// Here we have a comparison without types (===) so, JS sees both as equals
if(42 == "42"){
// Correct
if(true){
// This have no sense, because the callstack see the first item that is an integer, and can't compare
// the boolean as a number
if(42 == true){
console.log("continue")
@anibal21
anibal21 / Dockerfile
Created April 21, 2020 06:06
Dockerfile for old php5.6 projects
FROM php:5.6-apache
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libpq-dev
RUN apt-get install -y mcrypt libmcrypt-dev
RUN apt-get install -y zlib1g-dev
RUN docker-php-ext-install pdo_pgsql pgsql mcrypt zip
RUN apt-get install nano
@anibal21
anibal21 / README.md
Created March 12, 2020 15:44 — forked from valyala/README.md
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@anibal21
anibal21 / Dockerfile
Created January 28, 2020 06:12
Dockerfile for SPA Builds
FROM nginx:alpine
RUN apk add --update npm
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY . /usr/local/app/
WORKDIR /usr/local/app/
RUN npm install
@anibal21
anibal21 / ec6.js
Created January 3, 2020 05:01
EC6 functions to handle json data
/* Method to exclude items in a json, filtering by key index */
const excludeItemsInJson =
(jsonObject: any, filterParams: ReadonlyArray<string>) =
Object.keys(jsonObject)
.filter((key: string) => filterParams.includes(key) ? false : true)
.reduce((obj, item) => ({...obj, [item]: test[item]}) ,{})
/* Method to allow items in a json, filtering by key index.
Then a json will be returned with all the allowed items
*/