Skip to content

Instantly share code, notes, and snippets.

@pmarquees
pmarquees / editPage.js
Last active May 4, 2024 20:30
Edit page (bookmarklet)
javascript:document.body.contentEditable = 'true'; document.designMode='on'; void 0
@apisandipas
apisandipas / _html_entities.scss
Created January 14, 2014 16:02
HTML Entities map - The pseudo-element 'content' property doesnt accept normal (») style HTML entities. These variables below easy the pain of looking up the HEX codes...
/**
* The pseudo-element 'content' property doesnt accept normal (») style
* HTML entities. These variables below easy the pain of looking up the HEX codes...
*
* Referenced from http://www.danshort.com/HTMLentities/
*
* TODO: Add all the other entities? Worth it? Some day? Maybe?
*/
// Punctuation
@adamcbrewer
adamcbrewer / totype.js
Created November 21, 2013 12:42
JS: A Better typeof operator
/**
* A better, more reliable way to handle `typeof` checking.
*
* @source http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
*
*/
Object.toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
}
@adamcbrewer
adamcbrewer / clickEventType.js
Last active October 22, 2021 20:29
JS: Detect for supported 'touchstart' events.
/**
* Using default click events in touch-supported devices
* incurs a delay (in order to determine if the user is performing a gesture).
*
* Detecting for touchstart events using the foloowing, we can replace the default 'clicks'
* for touch events, making a snappier experience for mobile/touch devices.
* Use wisely as this could prevent some gestures from happening. If there are scrolling
* issues try swap out 'touchstart' for 'touchend'
*
*/
@stuntbox
stuntbox / gist:4557917
Last active March 23, 2023 03:32
Slightly smarter filtering to remove hard-coded width and height attributes from *all* images in WordPress (post thumbnails, images inserted into posts, and gravatars). Handy for responsive designs. Add the code below to the functions.php file in your theme's folder (/wp-content/themes/theme-name/ ). Remember to rename the function as needed to …
/**
* Filter out hard-coded width, height attributes on all images in WordPress.
* https://gist.github.com/4557917
*
* This version applies the function as a filter to the_content rather than send_to_editor.
* Changes made by filtering send_to_editor will be lost if you update the image or associated post
* and you will slowly lose your grip on sanity if you don't know to keep an eye out for it.
* the_content applies to the content of a post after it is retrieved from the database and is "theme-safe".
* (i.e., Your changes will not be stored permanently or impact the HTML output in other themes.)
*
@buschtoens
buschtoens / annularSector.js
Created December 2, 2012 19:14
Generate the path for an annular sector svg
function deg2rad(deg) {
return deg * Math.PI / 180;
}
function annularSector(centerX, centerY, startAngle, endAngle, innerRadius, outerRadius) {
startAngle = deg2rad(startAngle + 180);
endAngle = deg2rad(endAngle + 180);
var p = [
[centerX + innerRadius * Math.cos(startAngle), centerY + innerRadius * Math.sin(startAngle)]
@adamcbrewer
adamcbrewer / throttle.sh
Created October 11, 2012 07:55 — forked from apinstein/ipfw bandwidth throttle.sh
SH: ipfw bandwidth throttling
#!/bin/sh
#
# Use ipfw to throttle bandwidth.
# usage:
# ./throttle.sh # Throttle at default (60KB/s)
# ./throttle.sh 5 # Throttle at custom speed (5KB/s)
# ./throttle.sh off # Turn throttling off
# flush rules
ipfw del pipe 1
@Goles
Goles / CountryCodes.json
Created July 29, 2012 05:37
Country and Dial or Phone codes in JSON format
[{"name":"Israel","dial_code":"+972","code":"IL"},{"name":"Afghanistan","dial_code":"+93","code":"AF"},{"name":"Albania","dial_code":"+355","code":"AL"},{"name":"Algeria","dial_code":"+213","code":"DZ"},{"name":"AmericanSamoa","dial_code":"+1 684","code":"AS"},{"name":"Andorra","dial_code":"+376","code":"AD"},{"name":"Angola","dial_code":"+244","code":"AO"},{"name":"Anguilla","dial_code":"+1 264","code":"AI"},{"name":"Antigua and Barbuda","dial_code":"+1268","code":"AG"},{"name":"Argentina","dial_code":"+54","code":"AR"},{"name":"Armenia","dial_code":"+374","code":"AM"},{"name":"Aruba","dial_code":"+297","code":"AW"},{"name":"Australia","dial_code":"+61","code":"AU"},{"name":"Austria","dial_code":"+43","code":"AT"},{"name":"Azerbaijan","dial_code":"+994","code":"AZ"},{"name":"Bahamas","dial_code":"+1 242","code":"BS"},{"name":"Bahrain","dial_code":"+973","code":"BH"},{"name":"Bangladesh","dial_code":"+880","code":"BD"},{"name":"Barbados","dial_code":"+1 246","code":"BB"},{"name":"Belarus","dial_code":"+375","
@adamcbrewer
adamcbrewer / async-script.js
Created July 3, 2012 09:58
JS: Deferred, asynchronous script loading
<script type="text/javascript">
// Add a script element as a child of the body
function downloadJSAtOnload() {
var script = document.createElement("script");
script.src = "script.js";
document.body.appendChild(script);
}
// Check for browser support of event handling capability
if (window.addEventListener) {
@eirikbacker
eirikbacker / addEventListener-polyfill.js
Created June 3, 2012 19:30
addEventListener polyfill for IE6+
//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
(function(win, doc){
if(win.addEventListener)return; //No need to polyfill
function docHijack(p){var old = doc[p];doc[p] = function(v){return addListen(old(v))}}
function addEvent(on, fn, self){
return (self = this).attachEvent('on' + on, function(e){
var e = e || win.event;
e.preventDefault = e.preventDefault || function(){e.returnValue = false}
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true}