Skip to content

Instantly share code, notes, and snippets.

View JasonBBelcher's full-sized avatar
🎯
Focusing

Jason Belcher JasonBBelcher

🎯
Focusing
View GitHub Profile
@dexterlabora
dexterlabora / meraki-request.js
Last active July 18, 2019 00:33
A Meraki Dashboard API request wrapper to follow 301/302/307/308 redirects properly.
// Handles Meraki API requests. Has additional logic to follow the HTTP redirects properly and handle OrgID being converted to INTs
var request = require("request");
var JSONbig = require("json-bigint")({ storeAsString: true });
// Recursive function to follow Meraki API redirects
var requestMeraki = function(options, callback) {
request(options, function(error, res, data) {
//console.log('RESPONSE [ ' + res.statusCode + ' ]');
if (error) {
@markerikson
markerikson / redux-thunk-examples.js
Last active September 4, 2022 11:12
Redux-Thunk examples
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);
@joshnuss
joshnuss / app.js
Last active March 4, 2024 00:01
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@scrubmx
scrubmx / sublime-phpcs.md
Last active June 27, 2021 14:14
Setup Phpcs for Sublime Text

Setup Phpcs for Sublime Text

This plugin adds PHP CodeSniffer, PHP Code Beautifier and Fixer, PHP Coding Standards Fixer, the PHP Linter, PHP Mess Detector, Scheck support to Sublime Text.

For more information about this plugin such as features, installation requirements etc, please see: http://benmatselby.github.io/sublime-phpcs

Prerequisites

  • Download and install composer
curl -sS https://getcomposer.org/installer | php 
@chantastic
chantastic / on-jsx.markdown
Last active March 20, 2024 01:03
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@jonarnaldo
jonarnaldo / Sieve of Eratosthenes
Created February 25, 2014 04:32
Javascript Sieve of Eratosthenes
var Eratosthenes = function (n) {
this.array = function () {
var arr = [];
var output = [];
for (var i = 0; i < n; i++) {
arr.push(i);
}
return arr;
};
@jagregory
jagregory / gist:710671
Created November 22, 2010 21:01
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork git@github...my-fork.git