Skip to content

Instantly share code, notes, and snippets.

View h2rd's full-sized avatar

Igor Skrynkovskyy h2rd

View GitHub Profile
@h2rd
h2rd / doit
Created March 6, 2014 13:22 — forked from stantonk/doit
#!/bin/bash
# Source: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
yum groupinstall "Development tools"
yum install zlib-devel
yum install bzip2-devel openssl-devel ncurses-devel
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3

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

var a = [1,2,3,4,5,6,7,8];
Array.prototype.map = function(callback) {
var mapped = [];
for (var i = 0; i < this.length; i++) {
mapped[i] = callback.call(null, this[i]);
}
return mapped;
};
@h2rd
h2rd / gist:1699842
Created January 29, 2012 17:55 — forked from alright/gist:1698905
Vkontakte API class
<?php
class Vkapi {
protected $_access_token = '%access_token%';
protected $_client_id = 0;
public static function factory ()
{
$class = get_class();
@h2rd
h2rd / renamer.php
Created March 9, 2012 15:59
Translite with php
<?php
function slugify($text) {
return strtolower(strtr(trim($text), array(' '=>'_') ));
}
function translit($str){
static $tbl= array(
'а'=>'a', 'б'=>'b', 'в'=>'v', 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ж'=>'g', 'з'=>'z',
'и'=>'i', 'й'=>'y', 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', 'о'=>'o', 'п'=>'p',
@h2rd
h2rd / tmux.md
Created October 14, 2015 23:08 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

#! /usr/bin/env python
from os import fork, chdir, setsid, umask
from sys import exit
def main():
while 1:
#main daemon process loop
# Dual fork hack to make process run as a daemon

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

Compiling/Installing Node 0.8.4 (and Python 2.6, required by Node) on CentOS 5

Update system packages -- will migrate system forward to CentOS 5.8. (Optional?)

$ sudo yum update

Install the EPEL Repo:

# http://www.rabbitmq.com/tutorials/tutorial-two-python.html
import sys, time, json, logging
import pika
hostname = 'localhost'
logging.getLogger('pika').setLevel(logging.ERROR)
class RabbitMQ(object):
def __init__(self, hostname, queue, exchange = ''):
self.hostname = hostname