This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
import resource | |
import re | |
from collections import Counter | |
from threading import Thread | |
class ThreadLogFile(Thread): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collection.metaClass.eachWithPeek = { closure -> | |
def last = null | |
delegate?.each { current -> | |
if (last) closure(last, current) | |
last = current | |
} | |
if (last) closure(last, null) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[].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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} %]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
OlderNewer