Skip to content

Instantly share code, notes, and snippets.

View thejsj's full-sized avatar

Jorge Silva thejsj

View GitHub Profile
@thejsj
thejsj / gist:73d4ae8077dce91528b5bcc907d5f9b0
Created November 22, 2017 01:11
Creating user and assigning ownership inside Dockerfile
FROM ubuntu:latest
RUN useradd --uid 2000 -ms /bin/bash example
RUN mkdir -p /etc/example
RUN chown -Rv 2000 /etc/example
RUN ls -la /etc | grep example
USER 2000
CMD ["sh", "-c ls -la /etc | grep example"]
@thejsj
thejsj / install-mongo.sh
Created June 2, 2017 17:26
Install Mongo in Docker Container
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list
apt-get update -y
apt-get install -y mongodb-org
@thejsj
thejsj / 1-fixed.py
Last active April 20, 2017 06:19
Dani + Python
import requests
import xlwt
import datetime
from bs4 import BeautifulSoup
# Turn lines of code used multiples times into functions
def fetch_soup(uri):
response = requests.get(uri)
# Add "html.paser" so beautiful soup doesn't complain
return BeautifulSoup(response.content, "html.parser")
@thejsj
thejsj / keybase.md
Created April 13, 2017 18:38
keybase.md

Keybase proof

I hereby claim:

  • I am thejsj on github.
  • I am hiphipjorge (https://keybase.io/hiphipjorge) on keybase.
  • I have a public key whose fingerprint is 8470 BA42 28BE A599 BD6D 629E 0B0E 77B6 4B7B BD88

To claim this, I am signing this object:

@thejsj
thejsj / sieve.js
Created January 23, 2017 00:59
Get all prime number up to N
function sieve (n) {
let all = [...Array(n).keys()].map(x => true)
for (let i = 2; i <= Math.sqrt(n); i += 1) {
if (all[i]) {
for (let j = i * i; j < n; j += i) {
all[j] = false
}
}
}
return all.map((x, i) => {
@thejsj
thejsj / permutate.js
Last active January 23, 2017 00:50
All permutations for an array
// http://stackoverflow.com/a/22063440/2684055
function allPermutations (arr) {
function permutate (res, value, key, arr) {
if (arr.length <= 1) return [value]
// Eliminate current value
let result = arr.slice(0, key).concat(arr.slice(key + 1))
.reduce(permutate, [])
.map(perm => [value].concat(perm))
return res.concat(result)
}
@thejsj
thejsj / index.js
Created December 12, 2016 07:02
Javascript Cloning for Arrays
var a = [1, 2, 3]
var b = a // b now points to the same array as a
a === b // true
var c = [...a] // Makes a shallow copy of the array
c === a // false
a.push(4)
b // [1, 2, 3, 4]
c // [1, 2, 3]
a = null
b // [1, 2, 3, 4] Still point to the same array
@thejsj
thejsj / if-else-case.js
Created November 21, 2016 06:00
Ejemplos Para Jaime
var user = prompt("Where you at?").toUpperCase();
var isSingle = prompt("Are you single?").match(/yes/);
var isHappy = prompt("Are you happy?").match(/yes/);
switch(user) {
case 'HOME':
console.log("it is nice to have a home");
break;
@thejsj
thejsj / index.js
Created November 21, 2016 03:06
Return vs Else Example
'use strict'
// All these functions behave the same way
const getHello = function (a) {
if (a === true) {
return 'hello'
}
else {
return 'wow'
@thejsj
thejsj / fizzbuzz.hs
Last active August 31, 2016 04:50
FizzBuzz in Haskell
fizzbuzz :: Int -> String
fizzbuzz x | mod x 15 == 0 = "fizzbuzz"
| mod x 5 == 0 = "fizz"
| mod x 3 == 0 = "buzz"
| otherwise = show x
printAll [] = return ()
printAll (x:xs) = putStrLn x >> printAll xs
main = do