Skip to content

Instantly share code, notes, and snippets.

@tlhunter
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 http://stackoverflow.com/a/14231286/538646
*/
function averageGeolocation(coords) {
if (coords.length === 1) {
return coords[0];
}
@rvanzon
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
<template>
<div>
<my-line v-if="showLine" :data="lineData" :options="options">
</div>
</template>
<script>
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$) =>
action$
.ofType('SEARCH')
.mergeMap(
Observable
@fgilio
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('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@gaearon
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
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
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/org.nodejs.pkg.bom | 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
fredericcambon / sketchfab-v2-upload.sh
Last active May 6, 2020
Sketchfab - v2 api upload bash script
View sketchfab-v2-upload.sh
#!/bin/bash -e
##
# Sample script for uploading to sketchfab
# using the v2 api
##
##
# Uploading a model to Sketchfab is a two step process
#
@longkai
longkai / upload.html
Created Aug 16, 2013
fine uploader with jquery and bootstrap.
View upload.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fine Uploader - jQuery Wrapper Minimal Demo</title>
<link href="http://cdn.staticfile.org/twitter-bootstrap/2.3.2/css/bootstrap.min.css" 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
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