Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
agibsonsw / gist:5a4702c0b697c6f4bb66
Created January 8, 2016 22:13
Bookmarklet to add a comment box at selection
javascript: (function() {
var d = document;
var wrap = d.createElement('span');
wrap.style.position = 'relative';
wrap.className = 'wrap';
var cmt = d.createElement('textarea');
cmt.style.backgroundColor = 'yellow';
cmt.style.top = '1.5em';
cmt.style.position = 'absolute';
cmt.style.zIndex = '99';
@agibsonsw
agibsonsw / gist:a993c14ee172dfeb4d96
Created January 8, 2016 22:11
Bookmarklet to highlight selected word
javascript: (function() {
var els, i, txt = "";
if (window.getSelection) {
txt = window.getSelection();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
} else {
txt = "";
@agibsonsw
agibsonsw / gist:5bd9f18514683eab70a8
Created January 8, 2016 22:10
Bookmarklet to hide a page element on click
javascript:
(function(){
var d=document,useMine=true,prevEl;
function AddHandler(orig,mine) {
return function(e){
if(useMine)
mine(e);
else
if(orig)
orig(e);
@agibsonsw
agibsonsw / gist:409e59d0dcef906dbc41
Created January 8, 2016 22:09
Bookmarklet to display element stats on mouse over and click
javascript:
(function(){
var d=document,useMine=true,prevEl,info;
function addHandler(orig,mine){
return function(e){
if(useMine){
mine(e);
}
else
if(orig){
@agibsonsw
agibsonsw / gist:4254597
Created December 11, 2012 00:16
Temp tidied
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Overlay Simple</title>
<link href="https://developers.google.com/maps/documentation/javascript/examples/default.css"
rel="stylesheet">
<style>
@agibsonsw
agibsonsw / tidy.js
Created April 30, 2012 20:16
JS to tidy/align spaces
function tidySpaces() {
var olCode, spans, i, span_textnode, span_text, span_next, offLeft, newLeft;
if (document.getElementsByClassName) {
spans = document.getElementsByClassName('tidy');
if (spans != 'undefined' && spans.length) {
for ( i = 0; i < spans.length; i++ )
spans[i].style.paddingLeft = (spans[i].style.paddingLeft == '0px') ?
spans[i].prevValue : '0px';
return;
}
@agibsonsw
agibsonsw / PythonCompletions.py
Created March 14, 2012 22:05
Python completions (efficient)
import sublime, sublime_plugin
py_funcs = [
("abs()\tabs fn", "abs(${1:number})$0"),
("all()\tall fn", "all(${1:iterable})$0"),
("any()\tany fn", "any(${1:iterable})$0"),
("bin()\tbin fn", "bin(${1:integer})$0"),
("bool()\tbool fn", "bool(${1:[value]})$0"),
("bytearray()\tbytearray fn",
"bytearray(${1:${2:source}${3:[, encoding]}${4:[, errors]}})$0"),
@agibsonsw
agibsonsw / PythonCompletions.py
Created March 14, 2012 20:56
Python completions (ST) py fns and members
import sublime, sublime_plugin
py_funcs = [
("abs()\tabs fn", "abs(${1:number})$0"),
("all()\tall fn", "all(${1:iterable})$0"),
("any()\tany fn", "any(${1:iterable})$0"),
("bin()\tbin fn", "bin(${1:integer})$0"),
("bool()\tbool fn", "bool(${1:[value]})$0"),
("bytearray()\tbytearray fn",
"bytearray(${1:${2:source}${3:[, encoding]}${4:[, errors]}})$0"),
@agibsonsw
agibsonsw / PythonCompletions.py
Created March 13, 2012 22:57
Python completions (ST) functions/methods
import sublime, sublime_plugin
import re
py_compl = [ # standard Python functions
("abs()\tabs fn", "abs(${1:number})$0"),
("all()\tall fn", "all(${1:iterable})$0"),
("any()\tany fn", "any(${1:iterable})$0"),
("bin()\tbin fn", "bin(${1:integer})$0"),
("bool()\tbool fn", "bool(${1:[value]})$0"),
("bytearray()\tbytearray fn",
@agibsonsw
agibsonsw / PythonCompletions.py
Created March 13, 2012 18:46
Python completions (ST) global
import sublime, sublime_plugin
import re
py_compl = [
("abs\tabs fn", "abs(${1:number})$0"),
("all\tall fn", "all(${1:iterable})$0"),
("any\tany fn", "any(${1:iterable})$0"),
("basestring\tbasestring type", "basestring$0"),
("bin\tbin fn", "bin(${1:integer})$0"),
("bool\tbool fn", "bool(${1:[value]})$0"),