Skip to content

Instantly share code, notes, and snippets.

@nikic
nikic / password_hashing_api.md
Created September 12, 2012 15:04
The new Secure Password Hashing API in PHP 5.5

The new Secure Password Hashing API in PHP 5.5

The [RFC for a new simple to use password hashing API][rfc] has just been accepted for PHP 5.5. As the RFC itself is rather technical and most of the sample codes are something you should not use, I want to give a very quick overview of the new API:

Why do we need a new API?

Everybody knows that you should be hashing their passwords using bcrypt, but still a surprising number of developers uses insecure md5 or sha1 hashes (just look at the recent password leaks). One of the reasons for this is that the crypt() API is ridiculously hard to use and very prone to programming mistakes.

@krismas
krismas / argv.php
Last active June 19, 2025 09:19
A small MODX snippet to extract POST, GET, SESSION & COOKIE values
<?php
/*
* A small MODX snippet to extract POST, GET, SESSION & COOKIE values - (c) 2012-2016 ackwa.fr
*
* @version : 1.0.4
* @see : https://gist.github.com/gists/2853625
* @name : argv.php
* @author : [email protected]
* @usage : [[!argv?key=`myparam`&default=`1`]] -> return the value
* [[!argv?key=`myparam`&default=`1`&toph=`1`]] -> set [[+argv.myparam]]
@christianhanvey
christianhanvey / modx-snippets.php
Last active September 5, 2025 07:08
Useful snippets for MODX Revo
Snippet: [[SnippetName]]
Chunk: [[$ChunkName]]
System Setting: [[++SettingName]]
TV: [[*fieldName/TvName]]
Link tag: [[~PageId? &paramName=`value`]]
Placeholder: [[+PlaceholderName]]
<?php
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@goldsky
goldsky / autoload.fancybox.js
Created April 13, 2012 04:45
This snippet loads fancybox automatically to all images inside the #content area. Useful for user's images that are uploaded by TinyMCE.
$(document).ready(function() {
$("#content img").wrap(function() {
return '<a href="'+ this.src +'" />';
}).parent().fancybox();
});
@splittingred
splittingred / .htaccess
Created April 9, 2012 21:48
Example of how to use new REST server class in MODX 2.3+
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ rest/index.php?_rest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ rest/index.php [QSA,NC,L]
</IfModule>
@jaygilmore
jaygilmore / TinyMCECustomToolbar.txt
Created March 21, 2012 18:45
TinyMCE Minimal Custom Toolbar for MODX. Gives end users just the tools they need to create and publish content—nothing more.
formatselect,styleselect,bold,italic,underline,bullist,numlist,pastetext,image,modxlink,unlink,anchor,media,removeformat,separator,code,help
@edbo
edbo / lexiconToCsv.php
Created January 25, 2012 08:16
Php snippet to output lexicon file to csv
<%php
$fp = fopen('file.csv', 'w');
foreach ($_lang as $key => $field) {
fputcsv($fp, array(
'key' => $key,
'field' => $field
));
}
fclose($fp);
@Rob-ot
Rob-ot / Draggable.js
Created December 16, 2011 23:46
Draggable and dropable views for backbone, uses html5 drag and drop api, requires jquery and underscore, not tested in IE yet
return View.extend({
initialize: function () {
this.el.attr("draggable", "true")
this.el.bind("dragstart", _.bind(this._dragStartEvent, this))
},
_dragStartEvent: function (e) {
var data
if (e.originalEvent) e = e.originalEvent
e.dataTransfer.effectAllowed = "copy" // default to copy
@digibutt
digibutt / gist:1228932
Created September 20, 2011 11:55
Log a hit in a plugin in MODX
$tv = $modx->getObject('modTemplateVar', array('name' => 'hitcount'));
$criteria = array(
'tmplvarid' => $tv->get('id'),
'contentid' => $modx->resourceIdentifier
);
if(!$tvResource = $modx->getObject('modTemplateVarResource', $criteria)){
$tvResource = $modx->newObject('modTemplateVarResource');
$tvResource->set('value', 1);