Skip to content

Instantly share code, notes, and snippets.

View sawantuday's full-sized avatar

Uday R Sawant sawantuday

  • J.P. Morgan Chase & Co
  • India
View GitHub Profile
@sawantuday
sawantuday / send_remote_syslog.php
Created September 22, 2016 12:40 — forked from troy/send_remote_syslog.php
Send UDP remote syslog message from PHP (RFC 3164)
# replace PAPERTRAIL_HOSTNAME and PAPERTRAIL_PORT
# see http://help.papertrailapp.com/ for additional PHP syslog options
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
foreach(explode("\n", $message) as $line) {
$syslog_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, PAPERTRAIL_HOSTNAME, PAPERTRAIL_PORT);
}
socket_close($sock);
@sawantuday
sawantuday / phantomjsGoogleSearch
Created July 13, 2016 14:57 — forked from ndhu/phantomjsGoogleSearch
phantomjs. example on how to search google, collect links of search result and scrape multiple pages of the search result
/**
* Created by andy hulstkamp
*/
var webpage = require("webpage"),
fs = require("fs");
var debug = false,
pageIndex = 0,
allLinks = [],
@sawantuday
sawantuday / scraping-splash-dockerfile
Created July 6, 2016 16:15
Dockerfile for scraping splash, an alternative to PhantomJS
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
# Install, use dev tools, and then clean up in one RUN transaction
# to minimize image size.
ADD dockerfiles/splash/provision.sh /tmp/provision.sh
RUN /tmp/provision.sh \
prepare_install \
@sawantuday
sawantuday / uri.js
Created June 23, 2016 10:25 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@sawantuday
sawantuday / docker.py
Created June 19, 2016 18:16
Docker APIs implemented in python. Very bad code, trust me :(
from flask import Flask
from flask import Response
from flask import request
import requests
import json
app = Flask(__name__)
@app.route("/")
def hello():
@sawantuday
sawantuday / headless.md
Created June 17, 2016 09:18 — forked from addyosmani/headless.md
So, you want to run Chrome headless.

#If you're on Ubuntu or working with a Linux VM...

Step 1: Install the Ubuntu dependencies needed:

SSH into your server as a root or do sudo -i.

Then install necessary software:

apt-get update
@sawantuday
sawantuday / gist:a795fdd6fac97b51b7f6b6a1adf2218f
Created May 29, 2016 12:50 — forked from smoser/gist:4756561
boot a cloud image in kvm
## Install a necessary packages
$ sudo apt-get install kvm cloud-utils genisoimage
## URL to most recent cloud image of 12.04
$ img_url="http://cloud-images.ubuntu.com/server/releases/12.04/release"
$ img_url="${img_url}/ubuntu-12.04-server-cloudimg-amd64-disk1.img"
## download the image
$ wget $img_url -O disk.img.dist
## Create a file with some user-data in it
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<link rel="stylesheet" type="text/css" href="http://ak0.scstatic.net/1/cdn1.sweetcouch.com/shopify.css">
<style type="text/css">
table {width: 100%;font: 12px arial;}
th, td {min-width: 40px;text-align: center;}
th {font-weight: bold;}
@sawantuday
sawantuday / Dockerfile
Created May 13, 2016 08:36 — forked from yefim/Dockerrun.aws.json
Build a Docker image, push it to AWS EC2 Container Registry, then deploy it to AWS Elastic Beanstalk
# Example Dockerfile
FROM hello-world
@sawantuday
sawantuday / postData.php
Created May 9, 2016 09:53
Extract raw data from POST request.
<?php
$webhookContent = "";
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
$webhookContent .= fread($webhook, 4096);
}
fclose($webhook);
echo $webhookContent;