Skip to content

Instantly share code, notes, and snippets.

@swarajgiri
swarajgiri / axios-http-call.js
Last active March 20, 2020 07:51
Make a http call with axios
const axios = require('axios);
async function getFromAria( ){
try {
const ariaResponse = await axios({
url: '/downstreamUri',
// `method` is the request method to be used when making the request
method: 'get', // default
// `baseURL` will be prepended to `url` unless `url` is absolute.
@swarajgiri
swarajgiri / gist:3bdea6454406a6d13294c38eec5a4d39
Created January 30, 2019 07:56 — forked from jacqui/gist:983051
Redis SORT command examples
# Optimized for writes, sort on read
# LVC
redis.hset("bonds|1", "bid_price", 96.01)
redis.hset("bonds|1", "ask_price", 97.53)
redis.hset("bonds|2", "bid_price", 95.50)
redis.hset("bonds|2", "ask_price", 98.25)
redis.sadd("bond_ids", 1)
redis.sadd("bond_ids", 2)
@swarajgiri
swarajgiri / site.conf
Created April 27, 2018 10:16
nginx conf
upstream app {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name site.com www.site.com;
return 301 https://site.com$request_uri;
}
@swarajgiri
swarajgiri / aws-sns-example.js
Created September 26, 2017 09:21 — forked from tmarshall/aws-sns-example.js
aws-sdk sns example, in Node.js
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: '{AWS_KEY}',
secretAccessKey: '{AWS_SECRET}',
region: '{SNS_REGION}'
});
var sns = new AWS.SNS();
@swarajgiri
swarajgiri / cloudSettings
Last active February 26, 2020 15:11
Visual Studio code settings
{"lastUpload":"2020-02-26T15:11:20.568Z","extensionVersion":"v3.4.3"}
@swarajgiri
swarajgiri / blog-webpack-2.md
Created October 27, 2015 10:23 — forked from xjamundx/blog-webpack-2.md
From Require.js to Webpack - Part 2 (the how)

This is the follow up to a post I wrote recently called From Require.js to Webpack - Party 1 (the why) which was published in my personal blog.

In that post I talked about 3 main reasons for moving from require.js to webpack:

  1. Common JS support
  2. NPM support
  3. a healthy loader/plugin ecosystem.

Here I'll instead talk about some of the technical challenges that we faced during the migration. Despite the clear benefits in developer experience (DX) the setup was fairly difficult and I'd like to cover some of the challanges we faced to make the transition a bit easier.

@swarajgiri
swarajgiri / preprocessor_fun.h
Last active August 26, 2015 09:19 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@swarajgiri
swarajgiri / The Technical Interview Cheat Sheet.md
Last active August 29, 2015 14:28 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@swarajgiri
swarajgiri / gist:8f81606235b7ca3e9e4c
Last active August 29, 2015 14:25 — forked from jonathanmoore/gist:2640302
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

function mySexyMethod() {
return new Promise(function (resolve, reject) {
someAsync.method(params, function (err, data) {
if (err) {
return reject(err);
}
resolve(data);
})
});