Skip to content

Instantly share code, notes, and snippets.

View h2rd's full-sized avatar

Igor Skrynkovskyy h2rd

  • Route4Me
  • Lviv, Ukraine
View GitHub Profile
@h2rd
h2rd / gist:4518524
Created January 12, 2013 15:39
Sort array with blocks
NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) {
if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}
if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];
@h2rd
h2rd / f.py
Last active December 11, 2015 04:49
#!/usr/bin/python
# -*- coding: utf-8 -*-
from os import path
import subprocess
import time
import sys
def run(filename):
""" Run Subprocess scripts and control them """
#! /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:

@h2rd
h2rd / fb.php
Created March 12, 2013 22:14
Fb Challenge
<?php
# please use php -f input.php < input00.txt > output00.txt
$stdin = fopen('php://stdin', 'r');
$str = trim(fread($stdin, 1000));
fclose($stdin);
$total = strlen($str);
$count = 0;
$end = $start = 0;
@h2rd
h2rd / eventdispatcher.php
Created March 15, 2013 10:35
Symfony Event Dispatcher
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('event_name', function(Event $event) {
echo $event->getName(), ' Done', "\n";
});
$dispatcher->dispatch('event_name');

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:

import os
from scrapy.dupefilter import RFPDupeFilter
from scrapy.utils.request import request_fingerprint
class CustomFilter(RFPDupeFilter):
"""A dupe filter that considers specific ids in the url"""
def __getid(self, url):
mm = url.split("&refer")[0] #or something like that
# 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
@h2rd
h2rd / gist:5916403
Created July 3, 2013 08:39
mongoose add virtual field or tojson
Schema.virtual('id').get(function(){
return this._id.toHexString();
});
Schema.set('toJSON', {
virtuals: true
});
// or