Skip to content

Instantly share code, notes, and snippets.

View elundmark's full-sized avatar
💭
I may be slow to respond.

elundmark

💭
I may be slow to respond.
View GitHub Profile
@elundmark
elundmark / Format seconds To HH.MM:SS .js
Created March 9, 2011 13:59
Formats (milli)seconds to a more readable HH.MM:SS format, useful for the Youtube API
function formatTime(e, mi) {
if (mi) {
e = (e / 1000).toFixed(0);
}
var sForm = ( e % 60 ),
hours = "",
minutes = ( (e-sForm) / 60 ),
seconds = sForm < 10 ? "0" + sForm : sForm;
if (minutes>60) {
hours = ( (minutes-(minutes%60)) / 60 ) + ".";
@elundmark
elundmark / Copy selected filepath(s) to clipboard.sh
Created March 28, 2011 16:42
A Nautilus Script (as used in Ubuntu) to copy the selected file(s) path(s) to the clipboard.
#! /bin/bash
# fixed the old one -- it was useless when pasting in to a terminal, echo ads a new line character
echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"|xargs echo -n | /usr/bin/xclip -selection clipboard
notify-send -t 2000 "Sökvägen är nu kopierad :)"
@elundmark
elundmark / Copy text from file | Nautilus Script.sh
Created March 29, 2011 18:35
This script for Nautilus copies (a) file's (text) content to the clipboard manager.
#! /bin/bash
# Handles spaces in file, plus no trailing new line that 'cat file' would have added.
for arg
do
awk 'NR > 1 { print h } { h = $0 } END { ORS = ""; print h }' "$arg" | xclip -selection clipboard
done
notify-send -t 2000 "The content of the file was Copied :)"
@elundmark
elundmark / Use rm to move to Trash-bin
Created March 30, 2011 00:11
In the .bash_aliases file, add this to make a firendly rm command
# add this to ~/.bashrc ( or any alias file you have specified to include )
alias _rm='mv -f -t ~/.local/share/Trash/files'
# usage - can't say how many times this has savd my ass, rm is so easy to misuse.
$ _rm file.txt
@elundmark
elundmark / A console logger that doesn't break .js
Created March 30, 2011 01:31
An attempt to make a usable logger, that doesn't break if the console object isn't avaliable.
/*
Error free, [console] function shortcuts - First version
20110330 - http://elundmark.se/
Minified version: http://dl.dropbox.com/u/1907097/elundmark-se-UserScripts/logger.min.js
Includes console.---: log, info, warn, error, assert, dir, time, timeEnd
Example: _log(myObject); _warn("one value");
_error({ multiple:"values",foo:"bar" }); _assert(1<0);
*/
var _C = console, // I only use console explicitly below for readbility
hasConsoleLog = typeof _C.log === "function",
@elundmark
elundmark / Bash Aliases Collection
Created March 30, 2011 02:12
Some bash aliases for your terminal, tested on Ubuntu 10.10, dependencies may vary.
# lazy way to copy text to clipboard
copy () { echo "$1"|xargs echo -n | /usr/bin/xclip -selection clipboard ; }
# zip file/folder
zipf () { zip -r "$1".zip "$1" ; }
# make .tar.gz
tarf () { tar -cvzf "$1".tar.gz $1 ; }
# extract .tar.gz
xtarf () { tar xzvf "$1" -C "$2" ; }
@elundmark
elundmark / Copy MD5 hash to Clipboard .sh
Created March 30, 2011 16:46
An aliaas for the bash terminal to copy the given files md5 sum to the clipboard
# Paste into ~/.bash_aliases (Ubuntu)
copy_md5 () { echo -n $(md5sum $1 | cut -d ' ' -f 1) | /usr/bin/xclip -selection clipboard ; }
# Note that it doesn't add a new line, so it can be re-used inside the terminal right way.
# I made this Nautilus script as well, with a notification
#!/bin/bash
@elundmark
elundmark / web-server-switch.sh
Created May 21, 2011 13:41
Toggle apache mysql server on/off - Ubuntu
#!/bin/bash
STATUS=$(/etc/init.d/apache2 status)
if [[ $STATUS =~ "NOT" ]] ; then
ACTION="start"
else
ACTION="stop"
fi
if [ $ACTION = "start" ]
then
/etc/init.d/mysql start &&\
@elundmark
elundmark / Local_Pastbin_Script.sh
Created August 24, 2011 23:16
A local Pastbin alternative for Linux
#!/bin/bash
# A local Pastbin alternative for Linux (supercheesy)
# This pastes your Clipboard to a set file "here Pastebin.txt"
# It does NOT Append, but instead it makes it easier to read and
# Prepends new text to the file. Built in protection if the script
# is already running so nothing gets overwritten.
# FTP UPLOAD: Uncomment the block further down and fill in the
@elundmark
elundmark / gmark-with-selection.js
Created August 26, 2011 06:36
Google Bookmark Bookmarklet w Text Selection As Description
/* Copy and paste into the adress field */
javascript:(function(){var trunk= function(s,l){return s.substr(0,l-1)+(s.length>l?'...':'');},a=window,b=document,s=a.getSelection?a.getSelection():b.getSelection?b.getSelection():b.selection.createRange().text,s=s?s:"",c=function(s){return encodeURIComponent(s);},d=a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&annotation="+trunk(c(s),1100)+"&title="+c(b.title),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300)})();
/* Beautified */
(function() {
var trunk = function(s, l) {
return s.substr(0, l - 1) + (s.length > l ? '...' : '');
},