Skip to content

Instantly share code, notes, and snippets.

@skairunner
Last active September 8, 2017 07:15
Show Gist options
  • Save skairunner/4b6fbf0f69b64ad58f6812cf7aba45c4 to your computer and use it in GitHub Desktop.
Save skairunner/4b6fbf0f69b64ad58f6812cf7aba45c4 to your computer and use it in GitHub Desktop.
<head></head>
<script src="d3.min.js"></script>
<script>
var gamestate = [];
var emptyblock;
var moving = false;
document.addEventListener("DOMContentLoaded", function(){
gamestate.push({
x: 0,
y: 0,
n: "e",
empty: true
})
emptyblock = gamestate[0];
for (let i = 1; i < 9; i++) {
var o = {
x: Math.floor(i / 3),
y: i % 3,
n: i,
empty: false
};
gamestate.push(o);
}
var groups = d3.select("#puzzle")
.selectAll(".block")
.data(gamestate, function(d){ return d.n; })
.enter()
.append("g")
.classed("block", true)
.classed("isempty", function(d){return d.empty;})
.attr("id", function(d){return d.n;})
.attr("transform", function(d){
return "translate(" + d.x * 210 + "," + d.y * 210 + ")";})
.on("click", function(d){
if(d.empty) return;
newx = emptyblock.x;
newy = emptyblock.y;
emptyblock.x = d.x;
emptyblock.y = d.y;
d.x = newx;
d.y = newy;
d3.select(this)
.transition()
.duration(1000)
.ease(d3.easePolyInOut)
.attr("transform", "translate(" + d.x*210 + "," + d.y*210 + ")");
});;
groups
.append("rect")
.attr("width", 200)
.attr("height", 200);
groups.append("text")
.text(function(d){return d.n; })
.attr("x", function(d){return 85;})
.attr("y", function(d){return 110;})
.style("font-size", "60");
})
</script>
<style>
.isempty {display: none;}
.block {
fill: orange;
stroke: black;
stroke-width: 1px;
}
.block>text {fill:black;}
</style>
<body>
<svg id="puzzle" width=800 height=600 viewBox="-10 -10 800 600">
</svg>
</body>
from __future__ import print_function
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import selenium
import getpass
import time
import json
import subprocess
import os
driver = webdriver.Firefox()
driver.get("https://news.ycombinator.com/")
timeout = 30
for x in range(1):
things = driver.find_elements_by_css_selector(".athing")
for thing in things:
print(thing.find_element_by_css_selector(".title").text, end=" ")
print(thing.find_element_by_css_selector(".storylink").text)
driver.find_element_by_css_selector(".morelink").click()
textbox = driver.find_element_by_css_selector("#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > center:nth-child(4) > form:nth-child(4) > input:nth-child(1)")
textbox.send_keys("linus")
textbox.send_keys(Keys.ENTER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment