Skip to content

Instantly share code, notes, and snippets.

@forficate
forficate / gist:4179611
Created November 30, 2012 23:53
Show current working SVN branch at bash prompt
# Add the below to ~/.bash_profile
function parse_svn_branch {
# Note for mac users, use sed -nE 's/URL:.*\/(trunk|branches\/[^\/]*|tags\/[^\/]*).*/\1/p'
svn info 2> /dev/null | sed -rne 's/URL:.*\/(trunk|branches\/[^\/]*|tags\/[^\/]*).*/\1/p'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
@forficate
forficate / gist:5033866
Created February 25, 2013 22:19
Drupal input filters in scala for play framework
abstract trait InputFormat {
def format(source: String): String
}
object LineBreakFormatter extends InputFormat {
def format(source: String) = source.replaceAll("\n", "<br/>")
}
object HtmlEscapeFormatter extends InputFormat {
def format(source: String) = play.api.templates.HtmlFormat.escape(source).body
@forficate
forficate / Play framework init script
Created December 9, 2013 23:17
Play framework init script for CentOS 6
#!/bin/bash
# chkconfig: 345 20 80
# description: Play start/shutdown script
# processname: play
#
# Instalation:
# copy file to /etc/init.d
# chmod +x /etc/init.d/play
# chkconfig --add /etc/init.d/play
# chkconfig play on
@forficate
forficate / Play Framework Upstart script
Created December 9, 2013 23:23
Play framework upstart script
description "My Play App"
env USER=myappname
env GROUP=myappname
env HOME=/var/play/myappname
env PORT=9000
env ADDRESS=127.0.0.1
env EXTRA="-Xms128M -Xmx512m -server"
start on (filesystem and net-device-up IFACE=lo)

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

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

sub vcl_recv {
#FASTLY recv
if (req.request != "HEAD" && req.request != "GET" && req.request != "PURGE") {
return(pass);
}
#Dissable access to these at varnish
if (req.url ~ "install\.php|update\.php|cron\.php|apc.php|user/register") {
error 404 "Page not found.";
@forficate
forficate / delayedItervalArrayIterator.js
Created July 7, 2014 23:14
Javascript Array delayed interval iterator
//Iterates over each item in an array at a delayed interval (1500ms)
Array.prototype.iterate = function (callback, onFinished) {
var self = this;
(function get(index){
setTimeout(function(){
if(index < self.length) {
callback(self[index], index);
get(index + 1);
} else {
@forficate
forficate / main.rb
Last active August 29, 2015 14:10 — forked from anonymous/main.rb
Search my bitbucket repos from alfred
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require_relative "bundle/bundler/setup"
require "alfred"
require 'json'
basic_user = ENV['BB_USER_NAME']
basic_password = ENV['BB_PASSWORD']
# Get a refresh token for a client.
We use offline so we can access the account without the user needing to reauthenticate https://developers.google.com/identity/protocols/OAuth2WebServer
Also see the Web server applications sequence diagram at Web server applications
```
client_id=""
scopes="email profile"
csrf="some csrf token to validate"