Skip to content

Instantly share code, notes, and snippets.

@phuze
phuze / dropbox-php-auth.md
Last active February 4, 2023 23:27
Dropbox API V2: PHP Authentication Process
View dropbox-php-auth.md

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.
@rossriley
rossriley / bootstrap.php
Created September 9, 2015 18:25
Add a contenttype / id prefix to an image upload path
View bootstrap.php
<?php
// Appears in your bootstrap file, before the call to $app->run()
$app['upload'] = $app->extend('upload', function ($handler, $app) {
if ($app['request']->get('contenttype') == 'pages') {
if ($app['request']->get('contenttypeslug') && $app['request']->get('id')) {
$handler->setPrefix("/".$app['request']->get('contenttypeslug')."/".$app['request']->get('id'));
}
}
return $handler;
@niyazpk
niyazpk / pQuery.js
Created October 25, 2014 14:03
Add or update query string parameter
View pQuery.js
// 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)) {
@croxton
croxton / stash_conditionals.md
Last active April 8, 2018 02:24
Stash and conditionals in EE 2.9
View stash_conditionals.md

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}
@dennisfrank
dennisfrank / get_remote_db.sh
Created May 23, 2014 16:49
Shell script to import a remote database into local environment
View get_remote_db.sh
#!/bin/sh
# Import a remote database into a local database
# ----------------------------------------------
#
# Based on http://danherd.net/quick-script-synchronise-from-a-remote-expressionengine-database/
#
# Don’t forget chmod +x to make the script executable.
#
# Change the extension to .command to run the script directly from OS X Finder.
@octavian-nita
octavian-nita / module.js
Created February 18, 2014 15:35
JavaScript module pattern (inspiration: TypeScript, json2.js by Douglas Crockford)
View module.js
var Module;
(function (Module) {
'use strict';
var Greeter = (function () {
// Define the Greeter class:
function Greeter(message) {
this.greeting = message;
@narfbg
narfbg / hkdf.php
Created February 3, 2014 22:09
Experimental HKDF implementation for CodeIgniter's encryption class
View hkdf.php
/**
* 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
@brandonkelly
brandonkelly / templating.md
Last active July 29, 2022 14:58
Templating in EE vs. Craft
View templating.md
@amphibian
amphibian / gist:5414609
Created April 18, 2013 17:29
Quick example of one way to deal with Localize class methods which will be deprecated in ExpressionEngine 2.6
View gist:5414609
<?php
// Backwards-compatibility with pre-2.6 Localize class
$format_date_fn = (version_compare(APP_VER, '2.6', '>=')) ? 'format_date' : 'decode_date';
echo $this->EE->localize->{$format_date_fn}('%Y-%m-%d', $this->EE->localize->now);
// 2013-04-18
@Meroje
Meroje / 1-Entity-Repository-Controller-Pattern.md
Created November 18, 2012 20:53
Entity Repository in Laravel4
View 1-Entity-Repository-Controller-Pattern.md

Some Key points

[21:35:16] 1. Controllers call out to a repository to answer questions (like give me comments for a post, or are there any active users)
[21:35:27] so the repositories contain those business rules
[21:35:37] the entities (orm models) contain the application agnostic business rules
[21:35:42] like what makes a valid person
[21:36:09] 2. The repository interacts with the ORM to get the entities
[21:36:42] 3. The controller is merely responsible for processing the request, calling out to the appropriate repositories, and constructing the response
[21:36:52] All of the interactions are injected of course