Skip to content

Instantly share code, notes, and snippets.

View rich-97's full-sized avatar

Ricardo Moreno rich-97

View GitHub Profile
@rich-97
rich-97 / Factorial.java
Last active March 26, 2017 00:36
Java factorial
import java.util.Scanner;
public class Factorial {
public static int fact (int val) {
if (val == 0)
return 1;
return val * fact(val - 1);
}
@rich-97
rich-97 / cheatsheet-nodejs-en.md
Created March 5, 2017 23:08
A cheatsheet for modules of NodeJS.

process

/* Events */

process.on('exit', function(code) {})             // Emitted when the process is about to exit
process.on('uncaughtException', function(err) {}) // Emitted when an exception bubbles all the way back to the event loop. (should not be used)

/* Properties */
@rich-97
rich-97 / cheatsheet-javascript-es.md
Last active November 26, 2017 00:14
A cheatsheet for the objects (built-ins) of JS.

Math

/* Constantes */

Math.E       // número de Euler.
Math.PI      // número pi.
Math.SQRT2   // Raíz cuadrada de 2.
Math.SQRT1_2 // Raíz cuadrada de 1 / 2.
@rich-97
rich-97 / server.sh
Created February 24, 2017 00:10
Server nodejs in one line.
nodejs -e 'require("http").createServer((req, res) => { res.end("response"); }).listen(8080);'
@rich-97
rich-97 / server.js
Created February 7, 2017 19:05
A small server with nodejs in four lines.
require('http').createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
}).listen(8080);
@rich-97
rich-97 / postgres cheatsheet.md
Created January 17, 2017 00:56 — forked from apolloclark/postgres cheatsheet.md
postgres cheatsheet

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@rich-97
rich-97 / filter.js
Last active June 10, 2021 14:21
Example of pattern design oriented object in JavaScript.
$(document).ready(function () {
var $btn = $('.btn');
var $image = $('#img');
function Filter (config) {
this.target = config.target;
this.image = config.image;
this.filters = config.filters;
this.support = config.support === undefined ? true : config.support;
@rich-97
rich-97 / lsbin
Created December 24, 2016 20:35
List all binaries of directories in $PATH.
#!/bin/bash
list=${PATH//:/' '}
list=${list//\}/' '}
list=${list//\{/' '}
color () {
if [ -z $1 ]; then
tput setaf 1
else
@rich-97
rich-97 / fibo.sh
Last active December 16, 2016 03:12
Suseción Fibonacci con la Shell Bash.
# Fibo between 0 and 30.
len=30
arr=()
for (( i = 0; i < len; i++ )); do
if (( i > 0 )); then
let arr[i]="arr[i - 1] + arr[i - 2]"
else
let arr[i]=i
fi
@rich-97
rich-97 / reverse-str.c
Last active November 10, 2016 19:14
reverse a string
#include "stdio.h"
#include "string.h"
int main () {
char str[] = "hello";
int len = strlen(str);
for (int i = len; i >= 0; i--)
printf("%c", str[i]);