Skip to content

Instantly share code, notes, and snippets.

@al3xandr3
al3xandr3 / pretty.js
Created December 5, 2012 08:37
Pretty
// Add as browser bookmark:
// javascript:(function(){var d=document,s=d.createElement('scr'+'ipt'),b=d.body,l=d.location;s.setAttribute('src','https://raw.github.com/gist/4213877/pretty.js');b.appendChild(s)})();
// Loads javascript
// note that callback function needs be before calling loadJS(or inline)
// loadJS("http://code.jquery.com/jquery-latest.js", function() { $('my_element').hide(); });
var loadJS = function (url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
@al3xandr3
al3xandr3 / jgrowl.js
Last active October 10, 2015 19:07
Javascript Growl Type Alerts
// used here: https://gist.github.com/3665292
// loadJS('https://raw.github.com/gist/3736933/jgrowl.js', function(){ createGrowl("title", "content", false); });
// Loads javascript
// note that callback function needs be before calling loadJS(or inline)
// loadJS("http://code.jquery.com/jquery-latest.js", function() { $('my_element').hide(); });
var loadJS = function (url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
@al3xandr3
al3xandr3 / elements_tracking_debug.js
Last active October 10, 2015 08:57
Elements Tracking Debug
// Bookmark:
// javascript:(function(){var d=document,s=d.createElement('scr'+'ipt'),b=d.body,l=d.location;s.setAttribute('src','https://raw.github.com/gist/3665292/elements_tracking_debug.js');b.appendChild(s)})();
// loads javascript and executes some code when jQuery is loaded
// note that callback function needs be before calling loadJS(or inline)
// loadJS("http://code.jquery.com/jquery-latest.js", function() { $('my_element').hide(); });
var loadJS = function (url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
;; 5 samples => 2.9595399991095066
(mean (for [_ (range 10000)] (abs (- (mean weights) (mean (sample weights :size 5))))))
;; 10 samples => 2.0840500000983475
(mean (for [_ (range 10000)] (abs (- (mean weights) (mean (sample weights :size 10))))))
;; 40 samples => 1.0537100001504645
(mean (for [_ (range 10000)] (abs (- (mean weights) (mean (sample weights :size 40))))))
(use '(incanter core stats charts))
;; weights (in grams) of 50 randomly sampled bags of preztels
(def weights [464 447 446 454 450 457 450 442
433 452 449 454 450 438 448 449
457 451 456 452 450 463 464 453
452 447 439 449 468 443 433 460
452 447 447 446 450 459 466 433
445 453 454 446 464 450 456 456
447 469])
(defn sample-mean-error
[tdata tsize]
(mean (for [_ (range 10000)]
(abs (- (mean tdata)
(mean (sample tdata :size tsize)))))))
(defn progressive-sample-mean-error
[tdata]
(for [tx (range 2 (count tdata))]
(sample-mean-error tdata tx)))
(defmethod report :summary [m]
(with-test-out
(twitter-update (str "[coverager] " (:fail m) " failures, " (:error m) " errors."))
(println "\nRan" (:test m) "tests containing"
(+ (:pass m) (:fail m) (:error m)) "assertions.")
(println (:fail m) "failures," (:error m) "errors.")))
(defmethod report :summary [m]
(with-test-out
(println "\nRan" (:test m) "tests containing"
(+ (:pass m) (:fail m) (:error m)) "assertions.")
(println (:fail m) "failures," (:error m) "errors.")))
(import 'winterwell.jtwitter.Twitter)
(defn twitter-update [the_message]
(let [twitter (new Twitter "username" "password")]
(.updateStatus twitter the_message)))
(ns coverager
(:import (com.thoughtworks.selenium DefaultSelenium)
(org.openqa.selenium.server SeleniumServer)
java.util.Date
(java.io FileWriter)
(java.text SimpleDateFormat))
(:use clojure.contrib.zip-filter.xml)
(:require [clojure.zip :as zip]
[clojure.xml :as xml]))