Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby -w
require "rubygems"
require "stringex"
module Asciiable
def method_missing(method, *args)
return self.send(Regexp.last_match(1)).to_s.to_ascii if(method.to_s=~/(.+)_ascii/)
super
end
@kirushik
kirushik / gist:553248
Created August 27, 2010 12:15
Работа с xls из Руби
require 'rubygems'
require 'roo' # Надо установить библиотеку `gem install roo`
# Мне потребовалось дорешать зависимости руками: `gem install bones builder zip nokogiri spreadsheet google-spreadsheet-ruby spreadsheet-excel`
xls = Excel.new('http://www.nalog.ru/html/docs/svot/1nm2010.xls') # Эта строка автоматом загрузит xls-файл из веба и распарсит его в структуру
14.upto(22) do |line|
3.upto(7) do |cell|
print "#{xls.cell(line, cell)}\t" # Выведет фрагмент документа - строки с 14 по 22, колонки с 3 по 7
end
@kirushik
kirushik / gist:553265
Created August 27, 2010 12:29
Работа в MSWord из Руби
#Original code by Carlos Tirado, http://www.ruby-forum.com/topic/99742#214485
require 'win32ole'
word = WIN32OLE.new('word.application')
word.visible = true
word.documents.count
# open/create new document
word.documents.add
@kirushik
kirushik / gist:553326
Created August 27, 2010 13:17
Работа с pdf из Руби
require 'rubygems'
require 'pdf/toolkit' # Для работы требует pdftk и xpdf - в debain они доступны из пакетов
my_pdf = PDF::Toolkit.open("DrakonDescription.pdf")
text = my_pdf.to_text
text.each_line do |line|
puts line
end
# Выводит текстовое содержимое файла построчно. Русский переваривает нормально.
$KCODE = 'UTF8'
require 'rubygems'
require 'mechanize'
require 'docsplit'
require 'fastercsv'
a = Mechanize.new
@kirushik
kirushik / gist:659410
Created November 2, 2010 09:21
Десятипоточный тест диска в iozone
iozone -ec -t10 -r64K -s512K -i0 -F Z:\iozone\file01 Z:\iozone\file02 Z:\iozone\file03 Z:\iozone\file04 Z:\iozone\file05 Z:\iozone\file06 Z:\iozone\file07 Z:\iozone\file08 Z:\iozone\file09 Z:\iozone\file10
@kirushik
kirushik / config
Created February 14, 2011 23:13
from ROM Azure-1.0.1 (based on CyanogenMOD-6.0.0-Legend)
#
# Automatically generated make config: don't edit
# Linux kernel version: 2.6.29-5f084974
# Tue Aug 17 18:32:46 2010
#
CONFIG_ARM=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
CONFIG_GENERIC_GPIO=y
CONFIG_GENERIC_TIME=y
CONFIG_GENERIC_CLOCKEVENTS=y
@kirushik
kirushik / PrivateConstructor.as
Last active December 14, 2015 17:59
Нашёл на просторах интернетов (http://stackoverflow.com/a/14155541/181800) вот этот клёвый хак. При попытке создания лишних инстансов Direction сваливается с ошибкой, что в общем-то ожидаемое поведение в отсутствие приватных конструкторов.
package {
class Direction {
private static const CREATE:Object = {};
/*
* The actual enumeration values. Note that the sorting order doesn't matter.
*/
public static const NONE:Direction = new Direction(CREATE);
public static const UP:Direction = new Direction(CREATE);
public static const DOWN:Direction = new Direction(CREATE);
#!/bin/bash
REPO_ROOT=/srv/repo
PACKAGES_LOCATION=pool
METAINFO_LOCATION=$REPO_ROOT/dists/ubuntu/
RELEASE_FILE=$METAINFO_LOCATION/Release
PACKAGES_FILE=$METAINFO_LOCATION/testing/binary-amd64/Packages
cd $REPO_ROOT
@kirushik
kirushik / package.mk
Last active August 29, 2015 14:03
package.mk to add ets-cache into RabbitMQ build (should be placed in umbrella/ets-cache)
APP_NAME:=ets_cache
UPSTREAM_GIT:=https://github.com/blinkov/ets-cache.git
UPSTREAM_REVISION:=96e9a2a7c16127b8f4d0bdb279e28bd5600e4265
RETAIN_ORIGINAL_VERSION:=true
ORIGINAL_APP_FILE=$(CLONE_DIR)/src/$(APP_NAME).app.src
DO_NOT_GENERATE_APP_FILE=true