Skip to content

Instantly share code, notes, and snippets.

View jerson's full-sized avatar

Gerson Alexander Pardo Gamez jerson

View GitHub Profile
@kenzie
kenzie / quicksilver_score.php
Created April 29, 2010 11:26
Quicksilver string ranking algorithm in PHP
<?
// Quicksilver Score
//
// A port of the Quicksilver string ranking algorithm
// (re-ported from Javascript to PHP by Kenzie Campbell)
// http://route19.com/logbook/view/quicksilver-score-in-php
//
// score("hello world","axl") //=> 0.0
// score("hello world","ow") //=> 0.6
@csexton
csexton / com.sphinxsearch.searchd.plist
Created May 3, 2011 01:49
Thinking Sphinx launchd plist file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.sphinxsearch.searchd</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
@cyakimov
cyakimov / gist:1139981
Created August 11, 2011 15:49
Decode Facebook signed_request with NodeJS
//npm install b64url
//A signed_request for testing:
//WGvK-mUKB_Utg0l8gSPvf6smzacp46977pTtcRx0puE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyOTI4MjEyMDAsImlzc3VlZF9hdCI6MTI5MjgxNDgyMCwib2F1dGhfdG9rZW4iOiIxNTI1NDk2ODQ3NzczMDJ8Mi5ZV2NxV2k2T0k0U0h4Y2JwTWJRaDdBX18uMzYwMC4xMjkyODIxMjAwLTcyMTU5OTQ3NnxQaDRmb2t6S1IyamozQWlxVldqNXp2cTBmeFEiLCJ1c2VyIjp7ImxvY2FsZSI6ImVuX0dCIiwiY291bnRyeSI6ImF1In0sInVzZXJfaWQiOiI3MjE1OTk0NzYifQ
function parse_signed_request(signed_request, secret) {
encoded_data = signed_request.split('.',2);
// decode the data
sig = encoded_data[0];
json = base64url.decode(encoded_data[1]);
data = JSON.parse(json); // ERROR Occurs Here!
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@jrom
jrom / nginx.conf
Created February 7, 2012 17:14
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@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

@michalochman
michalochman / gist:3175175
Created July 25, 2012 08:53
Take screenshot with Behat/Mink after failed step
/**
* Take screenshot when step fails.
* Works only with Selenium2Driver.
*
* @AfterStep
*/
public function takeScreenshotAfterFailedStep($event)
{
if (4 === $event->getResult()) {
$driver = $this->getSession()->getDriver();
@terenceponce
terenceponce / instructions.md
Created September 26, 2012 08:25
Setting up Thinking-Sphinx on Mac OS X using Homebrew

Out of the box, Homebrew does a default installation on Sphinx:

$ brew install sphinx

However, if you're using MySQL, the thinking-sphinx gem won't work because it needs to use MySQL libraries.

If you managed to screw up the first time, uninstall sphinx first:

$ brew remove sphinx

@r-plus
r-plus / install_theos.sh
Created October 27, 2012 01:00 — forked from tom-go/install_theos.sh
Theos install script
#!/bin/bash
THEOS_INSTALL_DIR="/opt"
THEOS=${THEOS_INSTALL_DIR}/theos
BIGBOSS_REPO="http://apt.thebigboss.org/repofiles/cydia"
SUBSTRATE_REPO="http://apt.saurik.com"
# initial theos install directory check
if [ ! -d "$THEOS_INSTALL_DIR" ]; then
echo "making $THEOS_INSTALL_DIR"