This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
private | |
# Runs a rake task asyncronously in a child process | |
# | |
# for example, in any controller: | |
# async_rake("async:import_fixtures") | |
# async_rake("db:maintenance:cleanup", table: "things", ids: [12, 114, 539]) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A commented nginx configuration file for Ruby on Rails | |
# | |
# Author: Tommaso Pavese | |
# tommaso@pavese.me | |
# http://tommaso.pavese.me | |
# | |
# License: http://www.wtfpl.net/ | |
# | |
# | |
# Tested with: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "colorize" | |
REGISTRY = {} | |
DEBUG = false | |
SLEEP = 0.5 | |
def register(id) | |
mailbox = Queue.new | |
Thread.current[:process_id] = id | |
REGISTRY[id] = mailbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memory_kb | |
`ps -o rss= -p #{Process.pid}`.chomp.to_i | |
end | |
MEM_LOG = "current memory: %{mem} kB (+%{incr})".freeze | |
THR_LOG = "New Thread!".freeze | |
current_mem = 0 | |
loop do | |
m = memory_kb() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Timing do | |
def now do | |
:os.system_time(:milli_seconds) | |
end | |
# broken! the block is executed immediately | |
# | |
def ftime([do: block]) do | |
t0 = now | |
{ :ok, block, now - t0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
middleman build && | |
echo "--- middleman build complete" | |
git checkout master && | |
echo "--- cleaning old build" | |
(ls -1 | grep -v 'build' | xargs rm -rf ) && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/md5' | |
require 'base32' | |
require 'rqrcode' | |
require 'rotp' | |
def print_as_qr(string) | |
qrcode = RQRCode::QRCode.new(string) | |
filename = File.expand_path "~/Desktop/qr_#{rand(10_000)}.png" | |
qrcode.as_png.save(filename, :fast_rgb) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# Author: Tommaso Pavese | |
# tommaso@pavese.me | |
# www.wonderingmachine.com | |
# | |
# Simple script for markdown using: | |
# | |
# Redcarpet: https://github.com/vmg/redcarpet | |
# Rouge: https://github.com/jayferd/rouge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ENDPOINT_URL @"http://www.myawesomeserver.com/data/images" | |
// elsewhere: we will need this to send the request asynchronously | |
self.httpQueue = [[NSOperationQueue alloc] init]; | |
/** | |
* upload method | |
*/ | |
- (void)uploadImage:(UIImage*)image withImageName:(NSString*)imageName andParams:(NSDictionary*)paramsDict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'webrick' | |
require 'uri' | |
TARGET_URL = URI.parse "http://tommaso.pavese.me/back_to_work/" | |
redirect_callback = Proc.new do |request, response| | |
response.set_redirect WEBrick::HTTPStatus::TemporaryRedirect, TARGET_URL |
NewerOlder