Skip to content

Instantly share code, notes, and snippets.

tlhunter / average-geolocation.js
Created May 17, 2017
Calculate the center/average of multiple GeoLocation coordinates
View average-geolocation.js
* Calculate the center/average of multiple GeoLocation coordinates
* Expects an array of objects with .latitude and .longitude properties
* @url
function averageGeolocation(coords) {
if (coords.length === 1) {
return coords[0];
rvanzon / nuxt.config.js
Last active Oct 21, 2021
A way to use vue-chartjs as a plugin of Nuxt.js
View nuxt.config.js
// just an example. A cleaner way is to wrap the showLine-stuff in a dedicated component
<my-line v-if="showLine" :data="lineData" :options="options">
export default {
data () {
View redux-observable-dispatch-multiple-redux-actions-in-a-single-epic.js
There is no requirement that you make a one-to-one in/out ratio. So you can emit multiple actions using flatMap if you need to:
const loaded = (results) => ({type: 'RESULTS_LOADED', results});
const otherAction = (results) => ({type: 'MY_OTHER_ACTION', results});
searchEpic = (action$) =>
fgilio / axios-catch-error.js
Last active Nov 14, 2021
Catch request errors with Axios
View axios-catch-error.js
* Handling Errors using async/await
* Has to be used inside an async function
try {
const response = await axios.get('');
// Success 🎉
} catch (error) {
// Error 😨
gaearon / connect.js
Last active Nov 11, 2021
connect.js explained
View connect.js
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
andrewdelprete / async.js
Created Feb 28, 2016
Callback > Promises > Async / Await
View async.js
import axios from 'axios' // for promise examples
import request from 'request' // for callback example
* Services
const service = {
getPeople: () => axios({ url: 'http://localhost:3000/people' }),
getPlaces: () => axios({ url: 'http://localhost:3000/places' })
tonymtz / gist:d75101d9bdf764c890ef
Last active Nov 3, 2021
Uninstall nodejs from OSX Yosemite
View gist:d75101d9bdf764c890ef
# first:
lsbom -f -l -s -pf /var/db/receipts/ | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
fredericcambon /
Last active May 6, 2020
Sketchfab - v2 api upload bash script
#!/bin/bash -e
# Sample script for uploading to sketchfab
# using the v2 api
# Uploading a model to Sketchfab is a two step process
longkai / upload.html
Created Aug 16, 2013
fine uploader with jquery and bootstrap.
View upload.html
<!DOCTYPE html>
<meta charset="utf-8">
<title>Fine Uploader - jQuery Wrapper Minimal Demo</title>
<link href="" rel="stylesheet"
media="" />
<link href="/resources/libs/fineuploader/3.7.1/fineuploader-3.7.1.min.css" rel="stylesheet">
<style type="text/css">
.span12 {
hurjas / timestamp.js
Created May 11, 2012 — forked from jonkemp/timestamp.js
Print out a nicely formatted timestamp in JavaScript.
View timestamp.js
* Return a timestamp with the format "m/d/yy h:MM:ss TT"
* @type {Date}
function timeStamp() {
// Create a date object with the current time
var now = new Date();
// Create an array with the current month, day and time