Skip to content

Instantly share code, notes, and snippets.

@dubeme
dubeme / selenium-screenshotting.md
Created March 22, 2016 02:55 — forked from dannguyen/selenium-screenshotting.md
Using Selenium and Python to screenshot a javascript-heavy page

Using Selenium and Python to screenshot a javascript-heavy page

As websites become more JavaScript heavy, it's harder to automate things like screenshotting for archival purposes. I've seen examples and suggestions to use PhantomJS for visual testing/archiving of websites, but have run into issues such as the non-rendering of webfonts. I've never tried out Selenium until today...and while I'm not thinking about performance implications yet, Selenium seems far more accurate than PhantomJS...which makes sense since it actually opens a real browser. And it's not too hard to script to do complex interactions: here's an [example of how to log in to Twitter, write a tweet, upload an image, and send a tweet via Selenium and DOM element selection](https://gist.github.com/dannguyen/8a6fa49253c1d6a0eb92

@dubeme
dubeme / erase history
Created November 18, 2014 07:19
Script to delete all google chrome history
// https://superuser.com/questions/480646/how-can-i-delete-all-web-history-that-matches-a-specific-query-in-google-chrome
// Visit -> [chrome://history-frame/] to clear all history
// Visit -> [chrome://history-frame/#q=SEARCH_TERM] to clear all history with SEARCH_TERM
function remove() {
var inputs = document.getElementsByTagName('input');
try {
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == "checkbox"){
inputs[i].checked = true;
@dubeme
dubeme / Web API Snippet
Last active August 29, 2015 14:06 — forked from anonymous/gist:1c04bf2423579e9d2dcd
Consuming web api from android app
// These two need to be declared outside the try/catch
// so that they can be closed in the finally block.
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
// Will contain the raw JSON response as a string.
String forecastJsonStr = null;
try {
// Construct the URL for the OpenWeatherMap query
@dubeme
dubeme / Rearrange Array
Last active August 29, 2015 14:06
Amazon phone interview question
/*
Start from the end of the array
If I come across a non zero,
move it to before the last known
location of a non zero number
*/
void rearrangeArray(int[] nums)
{
int lastNonZero = nums.length - 1;
/// <summary>
/// A command whose sole purpose is to relay its functionality
/// to other objects by invoking delegates.
/// The default return value for the CanExecute method is 'true'.
/// <see cref="RaiseCanExecuteChanged"/> needs to be called whenever
/// <see cref="CanExecute"/> is expected to return a different value.
/// </summary>
public class RelayCommand : ICommand
{
private readonly Action _execute;
@dubeme
dubeme / BindableClassBase.cs
Created June 28, 2014 01:42
Base class for data binding
/// <summary>
/// This class is the base for all classes that neds to be bound to
/// eg: this.set(ref this._FIELD, value);
/// </summary>
public class BindableClassBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Sets a property, then fires the PropertChanged Event
@dubeme
dubeme / text.js
Created February 12, 2014 05:57 — forked from tj/text.js
var express = require('./')
var app = express();
app.use(function(req, res, next){
if (req.is('text/*')) {
req.text = '';
req.setEncoding('utf8');
req.on('data', function(chunk){ req.text += chunk });
req.on('end', next);
#!/usr/bin/env node
// Verify the most famous MD5 collision example in JavaScript, using nothing but
// built-in Node modules.
var crypto = require('crypto');
var ucs2encode = require('punycode').ucs2.encode;
var assert = require('assert');
var md5 = function(string) {
@dubeme
dubeme / rAF.js
Created May 12, 2013 10:40 — forked from paulirish/rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];