Skip to content

Instantly share code, notes, and snippets.

View anuragkapur's full-sized avatar

Anurag Kapur anuragkapur

View GitHub Profile
const myAlert = () => {
const x = "Foo Bar";
let count = 0;
const alerter = () => {
console.log(`${x} ${++count}`);
};
return alerter;
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@anuragkapur
anuragkapur / reduceExample.js
Created December 24, 2019 01:16
Example showcasing reduce function
// For the data set given below, find room which is false for all suspects (objects in the newDevelopment array)
const newDevelopment = [
{
name: 'Miss Scarlet',
present: true,
rooms: [
{kitchen: false},
{ballroom: false},
{conservatory: true},
{'dining room': true},
@anuragkapur
anuragkapur / fastly-latency-testing.sh
Last active November 8, 2016 12:41
Fastly latency compared to AWS API gateway
################
# Test script
################
#!/bin/bash
echo "fastlyTime,awsGatewayTime" >> responsetimes.log
while true
do
fastlyTime=`curl -o /dev/null -s -w %{time_total} -H 'X-Api-Key: 8Glz7vn2pM47AzzKmrXDU82h3S0Iud9n7wDgp3wM' https://round-trippa.ft.com/callback`
// Java 8
SendFaxOptions sendFaxOptions = new SendFaxOptions();
sendFaxOptions.setReplyAddress(Optional.of("reply@example.com"));
InterFAXClient interFAXClient = new InterFAXJerseyClient();
APIResponse apiResponse = interFAXClient.sendFax(
faxNumber,
"https://rest.interfax.net/outbound/documents/90bd5477d5944c6d884c610171b75258",
Optional.of(sendFaxOptions));
import sys
import json
from datetime import datetime
from dateutil.parser import parse
import paho.mqtt.client as mqtt
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
from pyspark.streaming.mqtt import MQTTUtils
@anuragkapur
anuragkapur / ox-clo-exercise-6b.md
Last active November 26, 2015 08:48
Bigdata analysis using Spark

Wind data and crime correlation

Part A

$ bin/pyspark --packages com.databricks:spark-csv_2.11:1.2.0

# load data from csv into a data frame
>>> df1 = sqlContext.read.format('com.databricks.spark.csv').options(header='true',inferschema='true').load('/home/oxclo/datafiles/wind2014/*.csv')
@anuragkapur
anuragkapur / hadoop.md
Last active November 24, 2015 11:59
Hadoop CLI Cheatsheet

Hadoop CLI Cheatsheet

List the entire HDFS

$ hadoop fs -ls -R /

List a dir

$ hadoop fs -ls /user/oxclo/output

Cat a file in the file system

$ hadoop fs -cat /user/oxclo/wind/SF37.csv

@anuragkapur
anuragkapur / awscli-cheatsheet.md
Last active May 17, 2017 22:59
AWS CLI Cheatsheet

#AWS CLI Cheatsheet

Describe all instances

aws ec2 describe-instances

Describe instance by tag and value

aws ec2 describe-instances --filter "Name=tag:Name,Values=oxclo06"

Describe instances and query the output to get InstanceId

aws ec2 describe-instances --filter "Name=tag:Name,Values=oxclo06" --query "Reservations[*].Instances[0].InstanceId"

if ( request from US ) {
route to US origin (-H Host:myapp-us.herokuapp.com)
if (response.status == 5xx)
route to EU origin
} else if ( request !from US ) {
route to EU origin (-H Host:myapp-eu.herokuapp.com)
if (response.status == 5xx)