Skip to content

Instantly share code, notes, and snippets.

View armand1m's full-sized avatar

Armando Magalhães armand1m

View GitHub Profile
@armand1m
armand1m / sequelize-bulk-upsert.js
Created October 18, 2016 14:22
A bulkUpsert function using Promises and the Sequelize API
module.exports = function bulkUpsert(model, key, values) {
function _find(where) {
return model.findOne({ where })
}
function _update(value, where) {
return model
.update(value, { where })
.then(() => _find(where))
}
@armand1m
armand1m / Dockerfile
Created November 1, 2016 16:31 — forked from alexellis/base.Dockerfile
Docker swarm service to mine into the Nice Hash pool
# Published on Docker Hub with above user alexellisio.
# If you want to rebuild your own copy, follow below instructions
# Build this on each type of machine so you have the correct CPU extensions.
FROM ubuntu:latest
WORKDIR /root/
RUN apt-get update -qy && \
apt-get install -qy cmake build-essential libboost-all-dev git ca-certificates \
--no-install-recommends
@armand1m
armand1m / Dockerfile
Last active March 10, 2024 14:54
Yarn cache compatible Dockerfile
FROM alpine
RUN apk add --update --no-cache nodejs
RUN npm i -g yarn
ADD package.json yarn.lock /tmp/
ADD .yarn-cache.tgz /
RUN cd /tmp && yarn
RUN mkdir -p /service && cd /service && ln -s /tmp/node_modules
@armand1m
armand1m / prepare-git-env.sh
Created December 1, 2016 16:23
One way of using Git on Rancher OS
alias git="docker run -ti --rm -v $(pwd):/git bwits/docker-git-alpine"
@armand1m
armand1m / .editorconfig
Created January 27, 2017 03:15
node.js .editorconfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
@armand1m
armand1m / logger.js
Created January 27, 2017 03:18
Helpful Logger using Squeak.js
'use strict'
const Squeak = require('squeak')
const logger = new Squeak()
.type('sync', {
color: 'cyan',
prefix: '+ sync'
})
.type('event', {
@armand1m
armand1m / geo.js
Created February 3, 2017 01:34 — forked from mkhatib/geo.js
A Javascript utility function to generate number of random Geolocations around a center location and in a defined radius.
/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
function generateRandomPoints(center, radius, count) {
var points = [];
for (var i=0; i<count; i++) {
@armand1m
armand1m / webkit-white-bg-autofill-hack.css
Created March 12, 2017 17:26
Removes webkit autofills horrible yellow color.
# Thanks to http://stackoverflow.com/questions/2781549/removing-input-background-colour-for-chrome-autocomplete
input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
box-shadow: 0 0 0px 1000px white inset;
-webkit-box-shadow: 0 0 0px 1000px white inset;
}
@armand1m
armand1m / login-npm-registry.sh
Created November 5, 2017 23:55
Login NPM Registry (useful for getting a token without having to `npm login`)
curl -s \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X PUT --data '{ "name": "username_user", "password": "password_here" }' \
https://registry.npmjs.org/-/user/org.couchdb.user:username_user
@armand1m
armand1m / withInitialData.js
Created November 15, 2017 22:38
Simple HOC for fetching data that is compatible with the SSR technique described by @BenLu here: https://medium.com/@benlu/ssr-with-create-react-app-v2-1-ee83fb767327
import React, { Component } from 'react';
const hasDataForThisKey = (staticContext) =>
(key) => staticContext && Object.keys(staticContext.data).includes(key);
const windowHasDataForThisKey = (window) =>
(key) => Object.keys(window.__DATA__).includes(key);
export default ({
key,