Skip to content

Instantly share code, notes, and snippets.

View marcelitocs's full-sized avatar
🎯
Focusing

Marcelito Costa marcelitocs

🎯
Focusing
View GitHub Profile
@marcelitocs
marcelitocs / mapConcurrently.js
Created July 28, 2023 19:51
Map Concurrently
function mapConcurrently(input, mapper, concurrency) {
let i = 0;
const result = [];
let pending = 0;
let done = false;
const promise = new Promise(function (resolve, reject) {
function startOne() {
if (done) return;
if (i == input.length) {
if (pending == 0) {
@marcelitocs
marcelitocs / idle-shutdown.sh
Created May 19, 2022 14:23 — forked from JustinShenk/idle-shutdown.sh
Google Cloud Platform (GCP) instance idle shutdown
#!/bin/bash
# Add to instance metadata with `gcloud compute instances add-metadata \
# instance-name --metadata-from-file startup-script=idle-shutdown.sh` and reboot
# NOTE: requires `bc`, eg, sudo apt-get install bc
# Modified from https://stackoverflow.com/questions/30556920/how-can-i-automatically-kill-idle-gce-instances-based-on-cpu-usage
threshold=0.1
count=0
wait_minutes=60
while true
@marcelitocs
marcelitocs / server.js
Created August 22, 2020 21:12 — forked from ryanoglesby08/server.js
A node.js SPA server that serves static files and an index.html file for all other routes.
/*
Incredibly simple Node.js and Express application server for serving static assets.
Given as an example from the React Router documentation (along with examples
using nginx and Apache):
- https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md#browserhistory
*/
const express = require('express');
const path = require('path');
@marcelitocs
marcelitocs / Webstorm and Nuxt.JS.md
Last active July 29, 2020 13:33
Webstorm and Nuxt.js
Preferences/Editor/Code Style/HTML -> Tabs and Indent (tab) -> Tab size, Indent, Continuation Indent to 2
Preferences/Editor/Code Style/HTML -> Other (tab) -> Spaces -> In Empty Tag (check this option)
Preferences/Editor/Code Style/HTML -> Other (tab) -> Do not indent children of -> Add script and style
@marcelitocs
marcelitocs / limitConcurrentGoroutines.go
Created January 26, 2019 18:37 — forked from AntoineAugusti/limitConcurrentGoroutines.go
Limit the maximum number of goroutines running at the same time
package main
import (
"flag"
"fmt"
"time"
)
// Fake a long and difficult work.
func DoWork() {
@marcelitocs
marcelitocs / update-golang.md
Created January 24, 2018 01:34 — forked from nikhita/update-golang.md
How to update the Go version

How to update the Go version

System: Ubuntu 14.04 (Trusty Tahr)

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@marcelitocs
marcelitocs / convert_coord_to_dms.js
Created January 15, 2018 20:58 — forked from fernandosavio/convert_coord_to_dms.js
Convert float coordinates to DMS (degree, minutes, seconds). Ex.: convert_coord_to_dms(e.g. 21.305728, -157.859647) -> 21° 18' 20.6208" N, 157° 51' 34.7292" E
function convert_coord_to_dms (lat, lon) {
/*
Se Lat é positivo é Norte, senão Sul
Se Long é positivo é Leste, senão Oeste
*/
var lat_orientation = lat < 0 ? "S" : "N",
lon_orientation = lat < 0 ? "W" : "E";
function get_dms(decimal) {
@marcelitocs
marcelitocs / gulpfile.js
Created October 6, 2017 20:00
gulp.js task to deploy code to remote servers
/*******************************************************************************
* Description:
*
* Gulp file to push changes to remote servers (eg: staging/production)
*
* Usage:
*
* gulp deploy --target
*
* Examples:
@marcelitocs
marcelitocs / app-adapters-application.js
Last active July 4, 2017 23:18
Ember Authentication
import DS from 'ember-data';
import Ember from 'ember';
import ENV from 'myapp/config/environment';
import appVersion from '../utils/app-version';
export default DS.JSONAPIAdapter.extend({
host: ENV.APP.API_URL,
init() {
this.set('appVersion', appVersion());
@marcelitocs
marcelitocs / extend.js
Created July 2, 2017 02:31
extend function like $.extend
function extend(){
for(var i=1; i<arguments.length; i++)
for(var key in arguments[i])
if(arguments[i].hasOwnProperty(key))
arguments[0][key] = arguments[i][key];
return arguments[0];
}