Skip to content

Instantly share code, notes, and snippets.

Loading bookmarklets with jQuery

I looked at a lot of solutions for this and here's what I've come up with:

(function getjQuery(callback) {
    if ('complete' === document.readyState) {
        var script = document.createElement('script');
        var target = document.documentElement;
 script.src = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
@kafene
kafene / example.php
Last active August 29, 2015 14:04 — forked from tekapo/example.php
wp_post_helper
<?php
require_once('/path/to/wordpress/wp-load.php');
require_once('class-wp_post_helper.php');
// initialize
$post = new wp_post_helper(array(
'post_name' => 'slug' , // slug
'post_author' => 1 , // author's ID
'post_date' => '2012/11/15 20:00:00' , // post date and time
'post_type' => 'posts' , // post type (you can use custom post type)
@kafene
kafene / parse_accept_header.php
Created July 18, 2014 06:18
Parse accept headers per RFC-2616
<?php
# ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
function parse_accept_header($header, $field = "") {
# save original value
$orig_header = $header;
$header = preg_replace('/[\r\n\t]/', '', $header);
$field = strtolower(trim($field));
@kafene
kafene / rc4.js
Created July 18, 2014 09:27 — forked from farhadi/rc4.js
rc4 functions in php and javascript
/*
* RC4 symmetric cipher encryption/decryption
*
* @license Public Domain
* @param string key - secret key for encryption/decryption
* @param string str - string to be encrypted/decrypted
* @return string
*/
function rc4(key, str) {
var s = [], j = 0, x, res = '';
@kafene
kafene / cb-aerosnap
Created July 22, 2014 20:48
A script for adding aero style window snapping to Openbox.
#!/usr/bin/env python
# cb-aerosnap:
# A script for adding aero style window snapping to Openbox.
# Written for CrunchBang Linux <http://crunchbang.org/>
# by Philip Newborough <[email protected]>
# ----------------------------------------------------------------------
# License:
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
#!/bin/bash
# References:
# - https://wiki.archlinux.org/index.php/Simple_Stateful_Firewall
# - http://www.tty1.net/blog/2007-02-06-iptables-firewall_en.html
# - http://rackerhacker.com/2010/04/12/best-practices-iptables/
# @ https://github.com/halhen/dotfiles/blob/master/.bin/firewall
function die {
echo "$@" >&2
@kafene
kafene / LICENSE
Last active August 29, 2015 14:04
openbox pipemenu for xrandr
Copyright (c) 2009, Seth House <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
@kafene
kafene / handlers.js
Created July 24, 2014 06:57
protocol and content handlers for web services
/**
* Sadly neither Chrome or Firefox fully support the functionality herein.
* Chrome supports only registerProtocolHandler, and Firefox supports
* a limited set of content handlers - at the moment it's pretty much
* just RSS feeds. These do work great in the older Opera 12 though.
*
* I've moved on from the abandoned Opera to Firefox but I put these
* here for future reference, hopefully browsers implement both
* navigator.registerProtocolHandler and navigator.registerContentHandler
* fully in the near future.
@kafene
kafene / com.ubuntu.desktop.pkla
Created July 24, 2014 10:12
/var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla (see: policykit-desktop-privileges)
[Mounting, checking, etc. of internal drives]
Identity=unix-group:admin;unix-group:sudo
Action=org.freedesktop.udisks.filesystem-*;org.freedesktop.udisks.drive-ata-smart*;org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.encrypted-unlock-system;org.freedesktop.udisks2.filesystem-fstab;
ResultActive=yes
[Change CPU Frequency scaling]
Identity=unix-group:admin;unix-group:sudo
Action=org.gnome.cpufreqselector
ResultActive=yes
@kafene
kafene / distances_slc_haversine.php
Created July 25, 2014 06:56
distance calculations using Spherical Law of Cosines and Haversine Formula
<?php
# Spherical Law of Cosines
function distance_slc($lat1, $lon1, $lat2, $lon2) {
$a = sin(deg2rad($lat1)) * sin(deg2rad($lat2));
$b = cos(deg2rad($lat1)) * cos(deg2rad($lat2));
$c = cos(deg2rad($lon2 - $lon1));
$distance = rad2deg(acos($a + $b * $c));
return round($distance * 60 * 1.1515, 4);
}