Skip to content

Instantly share code, notes, and snippets.

View ch1c0t's full-sized avatar

Anatoly Chernov ch1c0t

View GitHub Profile
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
@samstokes
samstokes / regex-groups-global.rb
Created November 18, 2009 03:28
How to extract groups from a regex match in Ruby without globals or temporary variables. Code snippets supporting http://blog.samstokes.co.uk/post/251167556/regex-style-in-ruby
if "foo@example.com" =~ /@(.*)/
$1
else
raise "bad email"
end
# => "example.com"
@ssokolow
ssokolow / pagination_example.sql
Created December 23, 2009 13:02
Reasonably efficient pagination without OFFSET (SQLite version)
-- Reasonably efficient pagination without OFFSET
-- SQLite version (Adapted from MS SQL syntax)
-- Source: http://www.phpbuilder.com/board/showpost.php?p=10376515&postcount=6
SELECT foo, bar, baz, quux FROM table
WHERE oid NOT IN ( SELECT oid FROM table
ORDER BY title ASC LIMIT 50 )
ORDER BY title ASC LIMIT 10
@kyanny
kyanny / echo.rb
Created February 24, 2010 17:43
Ruby socket TCPServer echo server
require 'socket'
gs = TCPServer.open(0)
socks = [gs]
addr = gs.addr
addr.shift
puts "server is on #{addr.join(':')}"
while true
nsock = select(socks)
@shelling
shelling / example-preseed.txt
Created August 17, 2010 05:48
Debian Preseed Example
#### Contents of the preconfiguration file (for lenny)
### Localization
# Locale sets language and country.
d-i debian-installer/locale string en_US.UTF-8
# Keyboard selection.
#d-i console-tools/archs select at
d-i console-keymaps-at/keymap select us
# Example for a different keyboard architecture
#d-i console-keymaps-usb/keymap select mac-usb-us
@wvanbergen
wvanbergen / convert_innodb_to_per_table_idb.rb
Created August 22, 2010 11:52
Convert InnoDB tables to use a separate idb files instead of the shared, giant ibdata1.
#!/usr/bin/env ruby
# Converts an InnoDB database that uses a shared InnoDB tablespace file (e.g. ibdata1) to use
# a separate file per table.
#
# - First change your my.cnf file to use separate files by adding "innodb_file_per_table" to
# the [mysqld] section. (This is safe: MySQL will revert to the giant file if it cannot find
# the per table file.)
# - Restart the MySQL server
# - cd to the directory of your database (cd /opt/mysql/data/mydb)
@iragsdale
iragsdale / async_resolver.rb
Created November 4, 2010 22:07
Asynchronous DNS resolver based on EventMachine and net-dns
require 'eventmachine'
require 'net/dns'
require 'net/dns/resolver'
module EM # :nodoc:
module Protocols
include Logger::Severity
class AsyncResolver < Net::DNS::Resolver
@scheibo
scheibo / Pasting in vim urxvtc arch linux
Created January 12, 2011 02:45
How to paste in vim
shift + middle click!
when set mouse=a is on, vim grabs all the mouse action, so in order to let X in on the fun use shift. in order to copy something from one part of the document use shift+highlight, and in order to paste, enter insert mode, toggle paste mode and shift+middle click. Very fun, quite a few steps to get a handle on though.
Alternatively, use 'set mouse=' (no a) to turn the mouse off and then just the X mouse will be functioning in vim. no shift is required, but make sure to still be pasting in insert mode and with paste on (without paste, autoindent ruins your day, without insert mode the stuff you're pasting will be interpreted as commands)
Finally, turn off bullshit flow control with
stty -ixon in your bashrc. Then you can properly get Ctrl+{S,V,X,Z,C} etc working but BE IN COMMAND MODE.
@nickyp
nickyp / self_signed_cert.rb
Last active September 4, 2023 23:46
create a self-signed certificate using ruby-openssl
We couldn’t find that file to show.
@jordansissel
jordansissel / netty-example.rb
Created April 11, 2011 06:22
Netty in JRuby
require "java"
require "netty-3.2.4.Final.jar"
# HELLO JAVA. I MISSED U.
java_import java.net.InetSocketAddress
java_import java.util.concurrent.Executors
java_import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory
java_import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory
java_import org.jboss.netty.channel.ChannelFactory
java_import org.jboss.netty.channel.ChannelPipelineFactory