Skip to content

Instantly share code, notes, and snippets.

View rhzs's full-sized avatar
🏠
Working from home

Ryuici rhzs

🏠
Working from home
View GitHub Profile
@rhzs
rhzs / RhezaSatriaHerokuLogReportStatistic.py
Last active August 29, 2015 14:12
Heroku Log Report Statistic (Num of called urls, Response time, and dyno)
#!/usr/bin/python
import time
import resource
import re
from collections import Counter
from threading import Thread
class ThreadLogFile(Thread):
Collection.metaClass.eachWithPeek = { closure ->
def last = null
delegate?.each { current ->
if (last) closure(last, current)
last = current
}
if (last) closure(last, null)
}
[].eachWithPeek { current, peek ->
assert false // shouldn't get here, nothing to iterate through
}
[1].eachWithPeek { current, peek ->
assert current == 1
assert peek == null // only 1 element, nothing to peek at
}
def results = []
@rhzs
rhzs / lazada_puller.rb
Last active August 29, 2015 14:26
Using capybara and poltergeist to pull lazada site
# This is an example - the usage of capybara and poltergeist to take screenshot of e-commerce website
# Later the implementation can be extended to pull data from the e-commerce website.
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
Capybara.run_server = false
Capybara.current_driver = :poltergeist
Capybara.app_host = 'http://www.lazada.co.id' # Indonesia e-commerce Lazada Site
@rhzs
rhzs / lazada_take_screenshot.js
Last active August 29, 2015 14:26
Using phantomjs to take lazada landing page screenshot (and pull data later on)
// To run type:
// phantomjs lazada_take_screenshot.js
// Output:
// see lazada.png
// Gotchas: not all AJAX are fully loaded!
var page = require('webpage').create();
page.open('http://www.lazada.co.id/', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('lazada.png');
@rhzs
rhzs / lazada_watir.rb
Created August 8, 2015 13:12
Using ruby & watir webdriver to take website screenshot
# Ecommerce Website Scrapping using ruby, watir webdriver and firefox
# To run:
# => ruby lazada_watir.rb
# Requirement:
# => gem install watir-webdriver
# => (all web driver dependencies)
require 'watir-webdriver'
browser = Watir::Browser.new :firefox
browser.goto "http://www.lazada.co.id/"
@rhzs
rhzs / lazada_crawl.groovy
Last active August 29, 2015 14:26
Simple java groovy example for data and web scrapping via import.io API
// Author: Rheza Satria (2015), Indonesia
// Purpose:
// Simple groovy example for data and web crawler/scrapping via import.io API.
// Note:
// Lazada is Indonesian e-commerce. Feel free to change with other e-commerce.
// Run:
// groovy lazada_crawl.groovy
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@rhzs
rhzs / zalora_jsoup.groovy
Last active August 8, 2018 00:56
Very Simple Example Java/Groovy and Jsoup library -- Crawler for Zalora Indonesia (e-commerce site)
// Download JSOUP library
@Grab('org.jsoup:jsoup:1.7.1')
// Connect and get Zalora URL via Jsoup
def doc = org.jsoup.Jsoup.connect("http://www.zalora.co.id/women/pakaian/dress/").get()
// Since the page loaded using AJAX we can't just crawl the CSS tag.
def script = doc.select("script")
def p = java.util.regex.Pattern.compile(/(?is)app.settings =(.*)app.i18n/);
def m = p.matcher(script.html());
@rhzs
rhzs / terminal_progress_bar.rb
Created August 8, 2015 18:20
Ruby Terminal Progress Bar Example
progress = 'Progress... ['
1000.times do |i|
j = i + 1
# add 1 percent every 10 times
if j % 10 == 0
progress << "="
print "\r"
print progress + " #{j / 10} %]"
@rhzs
rhzs / index.html
Created August 9, 2015 13:56
Go - Demonstrate simple HTML5 Server Side Events Example without Redis / RabbitMQ / anykind
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Server Side Event Example in Go</title>
</head>
<body>
Yey! {{.}}, here are some new messages about the
current time:<br>