Skip to content

Instantly share code, notes, and snippets.

View detro's full-sized avatar
🇺🇦
I may be slow to respond.

Ivan De Marino detro

🇺🇦
I may be slow to respond.
View GitHub Profile
@detro
detro / sleepsort.js
Created June 16, 2011 10:05
sleepsort in (Phantom)JS
// sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
function sleepSort(array, callback) {
var sortedCount = 0,
i, len;
for ( i = 0, len = array.length; i < len; ++i ) {
setTimeout((function(j){
return function() {
console.log(array[j]);
++sortedCount;
@detro
detro / invocation_patterns.js
Created February 12, 2012 21:20
JS Invocation Patterns
var foo, obj, Constructor, ClosuredScope;
aVariable = "I'm a String in a global (attached to 'window')";
// 'foo', but no 'bar'
foo = function(callMessage) {
console.log("\n\033[0;32m" + callMessage + " {\033[0m"); //< console.log(callMessage + "{");
console.log(aVariable);
console.log(this.aVariable);
console.log(window.aVariable);
@detro
detro / test-stack-error.js
Created June 14, 2012 09:06
Issues with Error reporting and Evaluation in PhantomJS upcoming 1.6
var p = require("webpage").create(),
pErrorCount = 1,
pConsoleMsgCount = 1;
p.onError = function(error, stack) {
console.log((pErrorCount) + " - ON PAGE ERROR: "+JSON.stringify(error)+"\n");
console.log((pErrorCount++) +" - ON PAGE ERROR STACK: "+JSON.stringify(stack)+"\n");
};
p.onConsoleMessage = function(msg) {
@detro
detro / script-FIXED.js
Created October 8, 2012 17:05 — forked from davisford/script-log.js
phantom cookies: now cookies are PERSISTENT as expected
var page = require('webpage').create();
phantom.cookiesEnabled = true;
console.log('\n\n cookies we know about => \n\n' + JSON.stringify(phantom.cookies, null, 2));
// spoof user-agent
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';
const USER = 'cvUg338yQa';
const PASS = 'GNyoqNKJK5';
@detro
detro / the_blue_winter_rose.md
Created December 4, 2012 17:39
The Blue Winter Rose

Blue Winter Rose

The Blue Winter Rose is a flower that grows in the glass gardens of Winterfell. It's pale blue the color of frost. Also, it's connected to the legend of Bael the Bard.

Legend

Bael the Bard climbed the Wall.

Index: .idea/libraries/phantomjsdriver.xml
===================================================================
--- .idea/libraries/phantomjsdriver.xml (revision 0)
+++ .idea/libraries/phantomjsdriver.xml (revision 0)
@@ -0,0 +1,11 @@
+<component name="libraryTable">
+ <library name="phantomjsdriver">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/third_party/java/phantomjs-driver/phantomjsdriver-1.0.0.jar!/" />
+ </CLASSES>
@detro
detro / raising_issues.uml
Created March 22, 2013 19:08
How to raise issues against an Open Source project (my take on it)
/'
Render this file with PlantUML.
Official website: http://plantuml.sourceforge.net/
'/
@startuml
start
:You found and <b>Issue</b>;
Daniel: you should run a blog.
@detro
detro / 0_reuse_code.js
Created November 4, 2013 17:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
private LogEntries getRemoteEntries(String logType) {
Object raw = executeMethod.execute(DriverCommand.GET_LOG, ImmutableMap.of(TYPE_KEY, logType));
@SuppressWarnings("unchecked")
List<Map<String, Object>> rawList = (List<Map<String, Object>>) raw;
List<LogEntry> remoteEntries = Lists.newArrayListWithCapacity(rawList.size());
for (Map<String, Object> obj : rawList) {
remoteEntries.add(new LogEntry(LogLevelMapping.toLevel((String)obj.get(LEVEL)),
(Long) obj.get(TIMESTAMP),
(String) obj.get(MESSAGE)));