Skip to content

Instantly share code, notes, and snippets.

jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
this.each(function() {
$(this).css({position:"relative"});
for (var x=1; x<=intShakes; x++) {
$(this).animate({left:(intDistance*-1)}, (((intDuration/intShakes)/4)), "swing")
.animate({left:intDistance}, ((intDuration/intShakes)/2), "swing")
.animate({left:0}, (((intDuration/intShakes)/4)), "swing");
}
});
return this;
@immutef
immutef / SecurityController.php
Created October 27, 2010 09:58
Symfony2 Security Form Login
<?php // src/Application/UserBundle/Controller/SecurityController.php
namespace Application\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\Security\SecurityContext;
class SecurityController extends Controller
{
public function loginAction()
@sspencer
sspencer / transparent-gif.js
Created October 31, 2010 22:27
Serve a transparent GIF from NodeJS
// Two ways to serve transparent GIF
var buf = new Buffer([
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
0x02, 0x44, 0x01, 0x00, 0x3b]);
res.send(buf, { 'Content-Type': 'image/gif' }, 200);
@unixpickle
unixpickle / Latest Video
Created December 23, 2010 05:04
A PHP script to get the latest video on a channel
function latestYoutube ($channel) {
error_reporting(E_ALL);
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $channel . '/uploads?max-results=20';
$sxml = simplexml_load_file($feedURL);
$i = 0;
foreach ($sxml->entry as $entry) {
$media = $entry->children('media', true);
$url = (string)$media->group->player->attributes()->url;
$index = strrpos($url, "&");
$url = substr($url, 0, $index);
@JCook21
JCook21 / composer.bat
Created February 6, 2012 14:02
Quick Batch file to add a 'composer' command to windows.
@echo off
if "%PHPBIN%" == "" set PHPBIN=C:\path\to\PHP\executable\dir\.\php.exe
"%PHPBIN%" "C:\path\to\composer.phar" %*
@evansolomon
evansolomon / gist:2274120
Created April 1, 2012 09:36
nginx WordPress multisite config
server {
listen 80 default_server;
server_name domain.com *.domain.com;
root /srv/www/domain.com/public;
access_log /srv/www/domain.com/log/access.log;
error_log /srv/www/domain.com/log/error.log;
location / {
index index.php;
@ebidel
ebidel / handle_file_upload.php
Created April 18, 2012 03:23
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@masnun
masnun / alexa.py
Created July 24, 2012 16:02
Python One-liner to get your site's Alexa Rank
#!/usr/bin/env python
import urllib, sys, bs4
print bs4.BeautifulSoup(urllib.urlopen("http://data.alexa.com/data?cli=10&dat=s&url="+ sys.argv[1]).read(), "xml").find("REACH")['RANK']
@orenitamar
orenitamar / country_codes.json
Created July 30, 2012 15:04
Two letter country code mapping, grouped by continent/region
{
"europe": {
"va": "vatican city",
"ch": "switzerland",
"ad": "andorra",
"ee": "estonia",
"is": "iceland",
"am": "armenia",
"al": "albania",
"cz": "czech republic",
@Adirael
Adirael / fix-wordpress-permissions.sh
Created August 17, 2012 23:16
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory