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
// Ref: http://progur.com/2017/02/create-mandelbrot-fractal-javascript.html | |
(function() { | |
var myCanvas = document.createElement("canvas"); | |
myCanvas.width = 600; | |
myCanvas.height = 600; | |
document.body.appendChild(myCanvas); | |
var ctx = myCanvas.getContext("2d"); |
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
function fireEventClick(elem){ | |
if(document.createEvent){ | |
var e = document.createEvent('MouseEvents'); | |
e.initMouseEvent('click', /* Event type */ | |
true, /* Can bubble */ | |
true, /* Cancelable */ | |
document.defaultView, /* View */ | |
1, /* Mouse clicks */ | |
0, /* Screen x */ | |
0, /* Screen y */ |
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
def timer(function): | |
""" A decorator that makes the decorated *function* return its execution time.""" | |
@functools.wraps(function) | |
def wrapper(*args, **kwargs): | |
t1 = time.time() | |
result = function(*args, **kwargs) | |
t2 = time.time() | |
print(" @time '{}': {:.4f} s.".format(str(function), t2-t1)) | |
return result |
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
// Compatible with java.sql.Timestamp/MySQL | |
(new Date ( | |
(new Date((new Date(new Date())).toISOString())).getTime() | |
- ((new Date()).getTimezoneOffset()*60000) | |
)).toISOString().slice(0, 19).replace('T', ' '); | |
// "2017-03-13 11:08:56" |
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
<svg width="36" height="36" viewBox="0 0 24 24"> | |
<path | |
fill="#fff" d="M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 | |
9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14, | |
17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63, | |
16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17, | |
16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2, | |
7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85, | |
6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 | |
17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81, |
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
/* | |
* Recursive function to initialize a n-dimensional array. | |
* @param *dims: | |
*/ | |
function emptyArray(dims) { | |
var arr = new Array(dims || 0); | |
var i = dims; | |
if (arguments.length > 1) { | |
var args = Array.prototype.slice.call(arguments, 1); |
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
# elt: WebElement | |
def robust_click(self, elt): | |
"""Click on the element, for the click() method is bugged half of the time""" | |
self.driver.execute_script("arguments[0].scrollIntoView(true);", elt) | |
action = ActionChains(self.driver) | |
action.move_to_element(elt).click().perform() | |
def js_click(self, elt): |
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
import java.io.FileInputStream | |
import java.nio.file.Paths | |
import play.api.http.HttpEntity | |
import akka.stream.scaladsl.StreamConverters | |
import play.api.mvc._ | |
import play.api.http.MimeTypes._ | |
import play.api.http.HeaderNames._ | |
import play.api.http.Status._ |
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
/** | |
* Return a Map[String,Any] of the field -> value pairs of the attributes of a class `c`. | |
*/ | |
def classToMap(c: AnyRef): Map[String, Any] = | |
// 'fold' syntax, starting with an empty map | |
(Map[String, Any]() /: c.getClass.getDeclaredFields) {(a, f) => | |
f.setAccessible(true) | |
a + (f.getName -> f.get(c)) | |
} |
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
set.seed(100) | |
data = c(rnorm(1000,mean=2,sd=1),rnorm(400,mean=6,sd=1.5)) | |
# linear | |
plot(sample(data), rep(0,length(data)), pch=4) | |
# with hist | |
hist(data, freq=FALSE, breaks=100) | |
points(sample(data), rep(0,length(data)), pch=4) |
NewerOlder