Skip to content

Instantly share code, notes, and snippets.

View thykka's full-sized avatar
🛠️

Moses Holmström thykka

🛠️
View GitHub Profile
function formatDuration (seconds) {
var ans = [], last, sec = seconds, min = 0, hrs = 0, dys = 0, yrs = 0;
if(sec === 0) { return "now"; }
while (sec >= 60 * 60 * 24 * 365) { yrs++; sec -= 60 * 60 * 24 * 365; }
while (sec >= 60 * 60 * 24) { dys++; sec -= 60 * 60 * 24; }
while (sec >= 60 * 60) { hrs++; sec -= 60 * 60; }
while (sec >= 60) { min++; sec -= 60; }
if(yrs >= 1) {ans.push( yrs > 1 ? yrs + " years" : "1 year" );}
if(dys >= 1) {ans.push( dys > 1 ? dys + " days" : "1 day" );}
if(hrs >= 1) {ans.push( hrs > 1 ? hrs + " hours" : "1 hour" );}
$(window).resize(changeorder);
$(document).ready(changeorder);
function changeorder(){
//inner page reordering
if ($(".page-left-column").css("float") == "none" ){
$( "#information-widget" ).appendTo( ".page-right-column" );
}
if ($(".page-left-column").css("float") == "left" ){
$( "#information-widget" ).prependTo( "#information-widget-container" );
@thykka
thykka / live.js
Created March 23, 2014 18:46
live.js - auto reload browser on content change
/*
Live.js - One script closer to Designing in the Browser
Written for Handcraft.com by Martin Kool (@mrtnkl).
Version 4.
Recent change: Made stylesheet and mimetype checks case insensitive.
http://livejs.com
http://livejs.com/license (MIT)
@livejs
@thykka
thykka / thing.js
Last active August 29, 2015 13:57
function beginCountdown (mins) {
var secs = mins * 60
var now = new Date()
var elapsed
var countdown = setInterval(function(){
elapsed = new Date() - now
if (elapsed/1000 < secs) {
updateProgress(elapsed/1000, secs)
} else {
updateProgress(1, 1)
@thykka
thykka / screenshot.bat
Created August 26, 2014 08:56
Take screenshots at regular intervals with NirCmd
set delay=5000
:loop
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,8%-%datetime:~8,6%
nircmd.exe savescreenshot "%datetime%.png"
nircmd.exe exec hide upload.bat "%datetime%.png"
ping 1.0.0.0 -n 1 -w %delay% >nul
goto loop
set FTP_hostname=12.34.56.78
set FTP_username=1337h4x0r
set FTP_password=rosebud
set FTP_remote_dir=screenshots
echo user %FTP_username%> ftpcmd.dat
echo %FTP_password%>> ftpcmd.dat
if defined FTP_remote_dir (
echo cd %FTP_remote_dir%>> ftpcmd.dat
)
Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & ".\screenshot.bat" & Chr(34), 0
Set WinScriptHost = Nothing
set delay=5000
:loop
:: Get locale-independent date to use as filename
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
:: Format the date
set datetime=%datetime:~0,8%-%datetime:~8,6%
:: Save a screenshot
nircmd.exe savescreenshot "%datetime%.png"
:: Upload the screenshot
nircmd.exe exec hide upload.bat "%datetime%.png"
:: [ v Config starts v ]
set FTP_hostname=12.34.56.78
:: Your FTP username (cannot be blank)
set FTP_username=1337h4x0r
:: Your FTP password (cannot be blank)
set FTP_password=rosebud
:: Remote folder to upload to (optional)
set FTP_remote_dir=screenshots
:: [ ^ Config ends ^ ]
Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & ".\screenshot.bat" & Chr(34), 0
Set WinScriptHost = Nothing