Skip to content

Instantly share code, notes, and snippets.

View jacobgarcia's full-sized avatar
👨‍💻
Mastering Go

Jacob Garcia jacobgarcia

👨‍💻
Mastering Go
View GitHub Profile
//This function counts the occurences
function findMostUsedWords(text) {
const matches = text.reduce((a, b) => {
a[b] = (a[b] + 1 || 1)
return a
}, {})
const max = Math.max(...Object.values(matches))
return Object.keys(matches).filter((word) => matches[word] === max)
}
// This function removes the excluded words
@jacobgarcia
jacobgarcia / counter.go
Created May 10, 2020 13:55
Channel counter implementation in Go without using sync.WaitGroup nor sync.Mutex. Only channels.
package main
import "sync/atomic"
func sum(counter *int32, i int32) *int32 {
atomic.AddInt32(counter, i)
return counter
}
func main() {
@jacobgarcia
jacobgarcia / babel.config.js
Created April 29, 2020 20:07
Babel config file for Expo Init. This is helpful for having src/* folder structrue
const path = require("path");
const paths = {
assets: path.resolve(__dirname, "assets"),
src: path.resolve(__dirname, "src"),
styles: path.resolve(__dirname, "styles")
};
module.exports = function(api) {
api.cache(true);
@jacobgarcia
jacobgarcia / count-folders.sh
Created April 25, 2019 20:32
Count folders in current directory
find . -mindepth 1 -maxdepth 1 -type d | wc -l
@jacobgarcia
jacobgarcia / git-pull-all.sh
Created April 25, 2019 20:01
Update multiple repos with one command
find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull
@jacobgarcia
jacobgarcia / repo-cloner.sh
Created April 25, 2019 19:47
Clone All Private Repos of An Organization
curl -u $token:x-oauth-basic -s https://api.github.com/orgs/$organization/repos\?page\=1\&per_page=100 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
@jacobgarcia
jacobgarcia / docker-nginx.sos
Created February 21, 2019 19:37
Docker NGINX proxy is garbage
docker stop proxy && docker rm proxy && docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --restart=always --name proxy --network proxy jwilder/nginx-proxy
@jacobgarcia
jacobgarcia / snippets.cson
Last active September 17, 2018 23:12
Snippets for Atom
'.source.js':
'Models Imports':
'prefix': 'modelimport'
'body': 'const $1 = require(path.resolve("models/$1"))'
'Return Error':
'prefix': 'return-error'
'body': 'if (error) { \n console.log($1, error) \n return res.status(500).json({ error: { message: $1 } })}'
@jacobgarcia
jacobgarcia / cju.js
Last active September 13, 2018 07:34
Node.js solution for Justón language interpreter
process.stdin.resume()
process.stdin.setEncoding('ascii')
let input = ''
const lex = 'sxocqnmwpfyheljrdgui'
const foo = 'udxsmpf'
const numbers = []
const lexicalMap = {}