Skip to content

Instantly share code, notes, and snippets.

View amir-rahnama's full-sized avatar

Amir Rahnama amir-rahnama

  • Stockholm, Sweden
View GitHub Profile
@amir-rahnama
amir-rahnama / gulpfile.js
Created October 26, 2015 13:34
Minimal Node.js Proxy Server Module (with Gulp)
var proxy = require('proxy.js')();
proxy.run();
@amir-rahnama
amir-rahnama / proxy.js
Last active November 3, 2015 14:32
Express.js Proxy to bypass cross-origin (CORS) HTTPS requests
var express = require('express'),
app = express(),
https = require('https'),
request = require('request'),
bodyParser = require('body-parser'),
PROXY_PORT = 12345,
HTTPS_POST = 443,
API_ENDPOINT = '/api',
CONTENT_TYPE = 'application/json',
HTTPS_HOST = 'sub.domain.com',
@amir-rahnama
amir-rahnama / server.js
Created November 10, 2015 23:12
Node.js TCP Server to generate Text Streams
// Server creates a stream of text in EXEC_INTERVAL time period
var net = require('net'),
EXEC_INTERVAL = 1000,
server = net.createServer(function(socket) {
setInterval(function() {
// Make sure data ends with a new line
socket.write('Echo ...' + '\n');
}, EXEC_INTERVAL);
}).listen(8000);
@amir-rahnama
amir-rahnama / server.py
Created November 20, 2015 10:42
A simple Python Socket Server
import socket
import random
HOST = '127.0.0.1'
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
@amir-rahnama
amir-rahnama / client.js
Created November 20, 2015 14:43
A simple Tornado (http://www.tornadoweb.org/en/stable/) WebSocket Server (with Client)
var ws = new WebSocket("ws://localhost:8888");
ws.onopen = function() {
ws.send("Hello, world");
};
//When Client Received a Message
ws.onmessage = function(evt) {
console.log(evt.data);
};
@amir-rahnama
amir-rahnama / map_reduce.py
Last active November 23, 2015 11:18
Send Result of MapReduce in Apache Spark (PySpark) over to a web socket: http://blog.ambodi.com/web-socket/
# pip install websocket-client
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
from websocket import create_connection
def take_rdd_send_to_socket(time, rdd, num=1000):
result = []
taken = rdd.take(num + 1)
print("-------------------------------------------")
print("Time: %s" % time)
@amir-rahnama
amir-rahnama / Capstone_Report.Rmd
Last active June 13, 2016 11:46
Capstone report for the Data Specialization Capstone project course
---
title: "Capstone First Milestone Report: Feature Engineering"
author: "Amir Hossein Rahnama"
date: "11 June 2016"
output: html_document
---
####Introduction
In this report, we are analyzing I have tried to start by showing a summary of all three data source from SwiftKey in terms of size. You can obtain the data with following code:
```{r eval=FALSE}
library(text2vec)
library(SnowballC)
library(doParallel)
library(microbenchmark)
library(tm)
con <- file("/Users/ara/dev/personal/r/final/en_US/en_US.blogs.txt", "r")
blogs <- readLines(con, encoding = 'UTF-8')
close(con)
@amir-rahnama
amir-rahnama / stackfile.yml
Last active October 22, 2017 00:58
Stackfile for Docker Cloud ElasticSearch Cluster (with Kibana)
es-master:
image: 'elasticsearch:latest'
command: 'elasticsearch --network.host=0.0.0.0 --node.master=true --cluster.name=escluster'
restart: always
es-develop:
image: 'elasticsearch:latest'
command: 'elasticsearch --network.host=0.0.0.0 --cluster.name=escluster --discovery.zen.ping.unicast.hosts=es-master'
deployment_strategy: high_availability
links:
- es-master
@amir-rahnama
amir-rahnama / Dockerfile
Created January 24, 2018 10:24
Dockerfile for your Flask application
FROM python:3
MAINTAINER Amir Rahnama "amirrahnama@gmail.com"
COPY . /app
WORKDIR /app
RUN pip install -r requirement.txt
RUN pip install --editable .
ENV FLASK_APP mini/app.py