Skip to content

Instantly share code, notes, and snippets.

@niyazpk
niyazpk / pQuery.js
Created October 25, 2014 14:03
Add or update query string parameter
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
@brandonkelly
brandonkelly / templating.md
Last active February 7, 2024 15:20
Templating in EE vs. Craft
@phuze
phuze / dropbox-php-auth.md
Last active February 2, 2024 13:46
Dropbox API V2: PHP Authentication Process

Effective September 2021, Dropbox will be deprecating long-lived access tokens.

This GIST generally describes how to authenticate requests to Dropbox API v2, for anyone working on a server-side PHP Dropbox implementation.

It's important to understand three types of codes you'll encounter:

  1. Access Code - this is a one-time code that represents user-granted app access.
  2. Access Token - this is short-lived token that provides access to Dropbox API endpoints.
  3. Refresh Token - this is a long-lived token that allows you to fetch a fresh Access Token.
@erikreagan
erikreagan / mac-apps.md
Created August 4, 2012 19:18
Mac developer must-haves

Mac web developer apps

This gist's comment stream is a collection of webdev apps for OS X. Feel free to add links to apps you like, just make sure you add some context to what it does — either from the creator's website or your own thoughts.

— Erik

@deizel
deizel / tail.php
Created October 6, 2012 22:08
PHP log tail example
<?php
if (isset($_GET['ajax'])) {
session_start();
$handle = fopen('/private/var/log/system.log', 'r');
if (isset($_SESSION['offset'])) {
$data = stream_get_contents($handle, -1, $_SESSION['offset']);
echo nl2br($data);
} else {
fseek($handle, 0, SEEK_END);
$_SESSION['offset'] = ftell($handle);
@mattattui
mattattui / gist:879249
Created March 21, 2011 10:08
Convert named HTML entities to numeric for XML compatibility
<?php
/* html_convert_entities($string) -- convert named HTML entities to
* XML-compatible numeric entities.
*/
function html_convert_entities($string) {
return preg_replace_callback('/&([a-zA-Z][a-zA-Z0-9]+);/S',
'convert_entity', $string);
}
@narfbg
narfbg / hkdf.php
Created February 3, 2014 22:09
Experimental HKDF implementation for CodeIgniter's encryption class
/**
* HKDF
*
* @link https://tools.ietf.org/rfc/rfc5869.txt
* @param $key Input key
* @param $digest A SHA-2 hashing algorithm
* @param $salt Optional salt
* @param $length Output length (defaults to the selected digest size)
* @param $info Optional context/application-specific info
* @return string A pseudo-random key
@croxton
croxton / stash_nested_embeds.md
Created October 29, 2012 14:23
Stash & template partials - nested embed

Required:

Stash 2.3.4 (beta) or later

Stash template directory

	/layouts/
		standard.html

	/partials/

listing.html

@croxton
croxton / stash_conditionals.md
Last active April 8, 2018 02:24
Stash and conditionals in EE 2.9

With Stash you have always been able to create global variables and evaluate them in the same template using if/else conditionals:

{exp:stash:set_value name="var" value="cheese" type="snippet"}

{if var == "cheese"}
  	We have cheese!
{if:else}
  	Where's the cheese, gromit? 
{/if}
@octavian-nita
octavian-nita / module.js
Created February 18, 2014 15:35
JavaScript module pattern (inspiration: TypeScript, json2.js by Douglas Crockford)
var Module;
(function (Module) {
'use strict';
var Greeter = (function () {
// Define the Greeter class:
function Greeter(message) {
this.greeting = message;