Skip to content

Instantly share code, notes, and snippets.

View rcanepa's full-sized avatar

Renzo Canepa rcanepa

View GitHub Profile
@rcanepa
rcanepa / 0_concepts.md
Last active August 16, 2019 20:04
JavaScript's prototype based inheritance

What is a prototype?

A prototype is a property functions have. This property points points to an object.

@rcanepa
rcanepa / basics.css
Created January 29, 2019 14:11
CSS resets for HTML form widgets
/*
* Because by default, some widgets do not inherit font-family and font-size from their parents.
* Many browsers use the system default appearance instead. To make your forms' appearance consistent
* with the rest of your content, we can add the following rules to our stylesheet:
*/
button, input, select, textarea {
font-family : inherit;
font-size : 100%;
}
@rcanepa
rcanepa / gist:982557491f1df1285f1b1dfe0f9e2f1e
Created September 12, 2018 14:15
Local HTTP Server with CORS
npm install http-server -g
#run
http-server -p 3000 --cors
More here:
https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
@rcanepa
rcanepa / numpy.py
Last active July 23, 2018 00:33
Numpy
# Element wise sum and multiplication
np.array([3, 1]) + np.array([2, 1]) # => np.array([5, 1])
np.array([3, 1]) * np.array([2, 1]) # => np.array([6, 1])
# Square root
np.sqrt(np.array([1,2])) # => array([1, 1.41421356])
# Magnitude of a vector
np.linalg.norm(np.array([1, 2])) # => 2.23606797749979
@rcanepa
rcanepa / pre-commit
Created May 1, 2018 15:27 — forked from hraban/pre-commit.md
Git pre-commit hook (.git/hooks/pre-commit) to prevent accidentally committing debug code (add NOCOMMIT in source comment)
#!/bin/sh
# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone:
@rcanepa
rcanepa / gist:887fa5ca213cf1d1ca7b493a49775dd1
Created January 17, 2018 20:24
Debugging scope on Angular 1
On the console, inspect an element that is part of the scope.
Then execute the following on the console:
> scope = angular.element($0).scope()
> scope.vm
@rcanepa
rcanepa / gist:e45eebc3af58c66497380421d9a3fcf4
Last active August 16, 2019 00:56
Docker cli commands
docker build -t friendlyname . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyname # Same thing, but in detached mode
docker container ls # List all running containers
docker container ls -a # List all containers, even those not running
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker image ls -a # List all images on this machine
@rcanepa
rcanepa / install_elasticsearch_osx.md
Created December 26, 2017 17:31 — forked from djonsson/install_elasticsearch_osx.md
OS X installation instructions for Elasticsearch + Kibana + Marvel

What is this?

Following this guide will set up a local Elasticsearch with Kibana and Marvel using Homebrew and Homebrew Cask

Prerequisites

If you already have Java installed on your system, skip steps Install Cask and Install Java

If you already have Java and Homebrew installed on your system, skip steps Prerequisites, start at Install Elasticsearch and Kibana after running $ brew update

Install Homebrew

  • $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Ref: https://stackoverflow.com/questions/582336/how-can-you-profile-a-script
- Using kcachegrind and pyprof2calltree
$ python -m cProfile -o script.profile script.py
$ pyprof2calltree -i script.profile -o script.calltree
$ kcachegrind script.calltree
@rcanepa
rcanepa / gist:c577a58dcd480575d67cc286e185e101
Last active August 16, 2019 00:57
Start python project with pyenv and pipenv
$ mkdir new-project
$ cd new-project
$ pyenv local <python-version>
$ pipenv install <package>
- About pipenv
https://docs.pipenv.org/
https://docs.pipenv.org/basics/
https://realpython.com/pipenv-guide/