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 / 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 / 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 / gulpfile.js
Last active July 16, 2018 14:54
Minimal gulpfile.js with Server, LiveReload and Watch Task for JS and Sass/Css
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
connect = require('gulp-connect'),
livereload = require('gulp-livereload'),
paths = {
scripts: ['scripts/*.js'],
html: ['*/*.html'],
style_css: 'styles/css',
style_sass: 'styles/sass'
},
@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 / README.md
Last active June 5, 2019 14:07
A simple Webpack (with Dev Server) + Gulp Configuration + LiveReload + Babel to playground where you can code ES6 without the need for React

A simple Webpack + Gulpfile configuration wihtout any need for React.js that assumes you have the following project structure:

node_modules/ bower_components/ scripts/

Entry script is in scripts/entry.js

You should run gulp && gulp build-dev and you are good to go.

@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}
@amir-rahnama
amir-rahnama / create-ngrams.R
Last active February 21, 2019 18:54
Create N-grams for large text-files (very fast)
source("fast-ngrams.R")
con <- file("path_to_file", "r")
data <- readLines(con, encoding = 'UTF-8')
close(con)
data <- clean(data)
onegram <- text_to_ngrams(decode(data), 1)
bigram <- text_to_ngrams(decode(data), 2)
trigram <- text_to_ngrams(decode(data, 3))