Skip to content

Instantly share code, notes, and snippets.

@nashingofteeth
nashingofteeth / pinboard-to-markdown.js
Last active October 27, 2023 01:25
convert Pinboard JSON export to Markdown
const fs = require('fs'),
data = fs.readFileSync('pinboard.json', { encoding: 'utf8', flag: 'r' }),
bookmarks = JSON.parse(data);
const dir = 'pinboard';
if (fs.existsSync(dir))
fs.rmSync(dir, { recursive: true, force: true });
if (!fs.existsSync(dir))
fs.mkdirSync(dir);
@nashingofteeth
nashingofteeth / copyToClipboard.js
Created August 30, 2017 22:52
copy data to clipboard without copy event
function copyText (text) {
const element = document.createElement('textarea');
element.value = text;
document.body.appendChild(element);
element.focus();
element.setSelectionRange(0, element.value.length);
document.execCommand('copy');
document.body.removeChild(element);
}
@nashingofteeth
nashingofteeth / anchor.js
Last active March 24, 2021 16:01
intercept paste event and convert urls in clipboard into links (for contenteditable elements)
document.addEventListener('paste', function (event) {
var clip = event.clipboardData.getData('text/plain');
var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var urlq = clip.match(urlRegex);
if (urlq != null) {
event.preventDefault();
var anchored = clip.replace(urlRegex, function(url) {
return '<a href="' + url +
'" style="cursor:pointer" onclick="window.open(this.href);return false">' +
url + '</a>';
@nashingofteeth
nashingofteeth / caret.js
Last active August 30, 2017 20:59
save and restore caret
var saveSelection, restoreSelection;
if (window.getSelection && document.createRange) {
saveSelection = function(containerEl) {
var range = window.getSelection().getRangeAt(0);
var preSelectionRange = range.cloneRange();
preSelectionRange.selectNodeContents(containerEl);
preSelectionRange.setEnd(range.startContainer, range.startOffset);
var start = preSelectionRange.toString().length;
@nashingofteeth
nashingofteeth / index.html
Last active August 29, 2015 14:14 — forked from anonymous/1.html
url to link conversion with A tag protection
<div contenteditable>http://google.com</div>
<script>
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 13) { // enter key
var text = document.querySelector('div').innerHTML;
var url = text.match(/(HTTP:\/\/)([a-zA-Z0-9.\/&?_=!*,\(\)+-]+)/i);
var foourl = url[0].replace("http", "foo");
document.foo = "foo";
document.http = "http";
<script type="text/javascript">
function setTime() {
var timeOut = false;
var currentDate = new Date();
var seconds = currentDate.getSeconds();
var minutes = currentDate.getMinutes() * 60;
var hours = currentDate.getHours() * 3600;
var myriaseconds = seconds + minutes + hours;
var mt = myriaseconds/10000;
document.body.innerHTML = mt.toPrecision(5);
@nashingofteeth
nashingofteeth / gist:3b154f76388afcf25192
Last active August 29, 2015 14:13
get cursor position
document.addEventListener("mousemove", function(event) {
mouseX = event.pageX;
mouseY = event.pageY;
document.body.innerHTML = mouseX + " " + mouseY;
}, false);
@nashingofteeth
nashingofteeth / gist:8e1049e844eecf93541c
Last active August 29, 2015 14:12
simple hotkey script
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 13 && evt.ctrlKey) {
evt.preventDefault();
alert('it works!');
}
};
@nashingofteeth
nashingofteeth / sand.html
Last active December 16, 2015 20:19
simple html editor
<html>
<head>
<link href="https://dl.dropboxusercontent.com/u/7984474/GitHub/sand/favicon.ico" rel="Shortcut Icon" />
<meta charset="UTF-8">
<title>sand v5 (ace)</title>
<script>
var editboxHTML =
'<script src="https://dl.dropboxusercontent.com/u/7984474/GitHub/sand/hotkeys.js"><\/script>' +
'<script>' +
' shortcut.add("Ctrl+Shift+X",function() { window.setCookie(); });' +
@nashingofteeth
nashingofteeth / outliner.html
Last active December 16, 2015 16:39
simple outliner
<script>
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.ctrlKey && evt.keyCode == 13) {
evt.preventDefault();
pasteHtmlAtCaret('<li style="margin-left: 15px;"> </li>');
}
if (evt.altKey && evt.keyCode == 13) {
evt.preventDefault();
pasteHtmlAtCaret('<li style="margin-left: -15px;"> </li>');