Skip to content

Instantly share code, notes, and snippets.

@ziadoz
ziadoz / index.php
Last active June 2, 2023 23:08
Simple PHP / jQuery CSRF Protection
<?php
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
// Start a session (which should use cookies over HTTP only).
session_start();
// Create a new CSRF token.
if (! isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}
@chestozo
chestozo / tumblr.api.post.text.js
Created September 2, 2012 08:25
Tumblr API usage with OAuth: creating a text post
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'http://www.tumblr.com/oauth/request_token',
'authorize_url': 'http://www.tumblr.com/oauth/authorize',
'access_url': 'http://www.tumblr.com/oauth/access_token',
'consumer_key': 'vGKikr2uBRsWoDZ947UjvSzA58HYEXDNjAer7VEXnLXlQt4Ozi',
'consumer_secret': 'JvofKKxQ2QSiVXVaWMBZQRzC5cI86YpJzAoouIkUdlvSeYXN2e',
'app_name': 'Photo post adder'
});
function stringify(parameters) {
@billerickson
billerickson / gist:3698476
Last active February 23, 2024 16:49 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@nodesocket
nodesocket / gist:3909074
Created October 17, 2012 23:53
Benchmark of for vs foreach in PHP
<?php
$elements = array();
////
// An array of 10,000 elements with random string values
////
for($i = 0; $i < 10000; $i++) {
$elements[] = (string)rand(10000000, 99999999);
}
@felipelavinz
felipelavinz / custom-mobile-feed.php
Last active November 11, 2021 22:13
A custom XML feed plugin for WordPress
<?php
/*
Plugin Name: Feed Noticias Móviles
Plugin URI: http://www.udd.cl
Description: Crea un feed de noticias para consumo en aplicación móvil
Version: 0.1
Author: Felipe Lavín (AyerViernes S.A.)
Author URI: http://www.ayerviernes.com
*/
@DinisCruz
DinisCruz / Version 1 (with static data).cs
Last active October 26, 2017 21:09
O2 Script - Send data to Google Analytics via get request (of Image)
//descriptions from http://www.lunametrics.com/blog/2011/10/04/utmgif-request-parameters/
var utmwv = "5.3.8"; // Tracking code version
var utms = "1"; // Session requests. Updates every time a __utm.gif request is made. Stops incrementing at 500 (max number of GIF requests per session).
var utmn = "1797201820"; // Unique ID generated for each GIF request to prevent caching of the GIF image
var utmhn = "teammentor-33-ci"; // Host name, which is a URL-encoded string
var utmcs = "ISO-8859-1"; // Language encoding for the browser. Some browsers don’t set this, in which case it is set to “-”
var utmsr = "1440x852"; // Screen resolution
var utmvp = "1440x751"; // Size of Viewing Pane
var utmsc = "32-bit"; // Screen color depth
var utmul = "en-us"; // Browser language
@ksafranski
ksafranski / SimpleStore.js
Last active July 2, 2022 15:25
Simple localStorage function with Cookie fallback for older browsers.
/**
* Simple localStorage with Cookie Fallback
* v.1.0.0
*
* USAGE:
* ----------------------------------------
* Set New / Modify:
* store('my_key', 'some_value');
*
* Retrieve:
@eduardozulian
eduardozulian / wp-customize-image-reloaded.php
Last active November 16, 2023 02:50
Extend WP_Customize_Image_Control class allowing access to files uploaded within the same context.
<?php
/**
* Customize Image Reloaded Class
*
* Extend WP_Customize_Image_Control allowing access to uploads made within
* the same context
*/
class My_Customize_Image_Reloaded_Control extends WP_Customize_Image_Control {
/**
* Constructor.
@mynameispj
mynameispj / dropdown.html
Last active December 22, 2019 16:05
Simple jQuery dropdown boxes that disappear when you click outside of them
<a class="drop-down-toggle">Click me to reveal drop down box below...</a>
<div class="drop-down-wrapper">
Hello, I will be revealed!
</div>
@gregrickaby
gregrickaby / wordpress-transient-caching.php
Last active January 2, 2019 10:45
WordPress Transient Caching
<?php
/**
* Setup wp_query arguments for the loop. Cache the results for 4 hours.
*
* @link http://codex.wordpress.org/Transients_API
*/
// Check for transient
if ( false === ( $my_query = get_transient( 'foo_featured_posts' ) ) ) {