VS Code, virtualenvironment and Django; simple setup

Just found out that VS code is genious:

in shell, make a project folder: >mkdir myproject >cd myproject >python3 -m virtualenv myproject_venv >source myproject_venv/bin/activate >pip install Django >django-admin startproject myproject .
Code language: Bash (bash)

Now if you open the “root” myproject folder, the one created on line 1, VS code will detect the django project and the virtual environment. So hit F5 to to run the server in debug mode.


Simple function to run javascript after specific content is loaded.
jQuery dependant.
Useful for dealing with resizing iframes after content is loaded to avoid scroll bars in the iframe. Also serves as an alternative to waitForKeyElement when tinkering with userscripts et.


/* Usage: waitForAsyncElement(selector, code, delay, timeout, fallback); Breakdown: selector: jQuery selector as string: "#yourElementHere" code: function with code to run: function(){"code here"}; delay: delay in ms after element is loaded: default 30ms timeout: stop execution if element is not loading: default 5000ms fallback: if timed out run fallback, example: function(){alert("async did not load")")} Example: */ waitForAsyncElement("#some-data", function(){ console.log($("#some-data").val()); }) //Example with fallback: waitForAsyncElement("#some-data", function(){ console.log($("#some-data").val()); }, 30, 5000, function(){ console.log("#some-data did not load"); }) /* Example for dealing with resizing iFrame after its loaded: Note the extra 300ms delay to wait for iframe content to load, iFrame.onload could have been used instead, but seem to fail on mobile. */ onElementLoaded("#iFrame1", function(){ var iFrame = document.getElementById('iFrame1'); iFrame.height = iFrame.contentWindow.document.body.scrollHeight + 100; }, 300);
Code language: JavaScript (javascript)


var waitForAsyncElement = function(elementSelector, callback, delay = 30, timeoutms = 5000, timeoutFallback = function(){return}){ var intervl = setInterval(function(){ if (jQuery(elementSelector).length){ clearInterval(intervl); setTimeout(() => {callback()}, delay); } }, 300); if (timeoutms !== 0){ setTimeout(() => { clearInterval(intervl); timeoutFallback(); }, timeoutms); } };
Code language: JavaScript (javascript)


Public Domain or MIT, whichever suits you best. However please keep me in the loop if you build on the function, make and improvements and such 🙂

Save and load more reliably with in userscript, maybe.

So, been messing around with userscript lately, in tampermonkey. And hence had a few problems saving and loading with GM_setValue and GM_getValue. There are a couple of scrips out there to sort this for you, but none that i was able to get to work. So I’ve wrapped my own version up, which also compresses via LZstring. (google it).

d.save(“float”, 12.34);

Continue reading

mirror website with wget

wget -r -np -k -nc --execute="robots = off" --wait=5 -E <url>

-r: recursive
-np: no parent directories
-k: convert links to local
-nc: no clobber, skip if file already downloaded
–execute=”robots = off”: ignore robots.txt
–wait=5: wait in between requests
-E: add .html to the end of filenames