Skip to content

Instantly share code, notes, and snippets.

View telamon's full-sized avatar
🥲
probing for lost signals

Tony Ivanov telamon

🥲
probing for lost signals
View GitHub Profile
@telamon
telamon / array_group.rb
Created April 27, 2011 12:55
JS array.inGroupsOf() behaviour for Ruby
class Array
def groups_of(s)
resp = []
g=[]
self.each do |i|
g << i
if g.count == s
resp << g
g= []
end
@telamon
telamon / short_hash.rb
Created May 16, 2011 16:34
Really short(6chars) hash method
# Really short hash, (no extra collisions besides the known CRC32 )
# Correct term for this encoding should be "Trimmed Urlsafe Base Encoded CRC32 Hash" or TUBECH?.. two-bitch encoding, lol.
# String.send(:include , ShortHash)
# "Hello World".short_hash # => "VrEXSg"
module ShortHash
require 'base64'
@telamon
telamon / rdhcpd.rb
Created May 20, 2011 23:58
Pure ruby DHCP server
' Copyright (c) 2007, Tony Ivanov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
@telamon
telamon / effect_rotate.js
Created May 24, 2011 16:46
Effect.Rotate patch for Scriptaculous
Element.getTransform= function (element){
var properties = [
'transform',
'WebkitTransform',
'MozTransform',
'msTransform',
'OTransform'
];
var p;
while (p = properties.shift()) {
@telamon
telamon / gravatar_helper.rb
Created May 24, 2011 17:37
Simple Gravatar helper for Rails
module GravatarHelper
def gravatar_tag(email,*args)
opts = args.extract_options!
opts[:class]||=""
opts[:class]+=" gravatar"
size = opts.delete(:size) || 80
require 'digest/md5'
default=""
@telamon
telamon / buffer_mapper.rb
Created June 1, 2011 13:38
BufferMapper provides lazy-loading bindings for a binary buffer
module Raumod::BufferMapper
# See http://ruby-doc.org/core/classes/String.html#M001112
# for map types.
def data_map;@data_map;end
def data;@data;end
def data_entry(method)
offset = data_map[method][:offset]
type = data_map[method][:type]
d = data[offset..-1].unpack(type)
@telamon
telamon / socksproxy.js
Created August 5, 2011 12:42
Socks5 proxy implementation in Node.JS
// http://www.ietf.org/rfc/rfc1928.txt
// Tested with: curl http://www.google.se/ --socks5 1080 --proxy-user foo:bar
var States = {
CONNECTED:0,
VERIFYING:1,
READY:2,
PROXY: 3
};
@telamon
telamon / ArduinoExample.pde
Created October 10, 2011 23:32
Arduino+Processing Oscilloscope
#include "oscilloscope.h"
#define ANALOG_IN 0
void setup() {
Serial.begin(9600);
}
void loop() {
int val = analogRead(ANALOG_IN);
@telamon
telamon / telnet.js
Created February 4, 2012 23:13
Telnet client in node
var net = require('net');
var client = net.connect(parseInt(process.argv[3]),process.argv[2],function(){
client.setEncoding('utf8');
console.log('Connected!!');
client.on('data',function(chunk){
console.log(chunk);
});
process.stdin.resume(); // Activate STDIN
process.stdin.setEncoding('utf8'); // Set it to string encoding
process.stdin.on('data',function(chunk){ // Pipe STDIN to Socket.out
@telamon
telamon / gobmod.js
Created February 14, 2012 22:15
Quick'n'Dirty FlodJS implementation.
window.gobmod={};
window.gobmod.attachPlayer = function(elem){
elem = $(elem);
var player = new Element('a',{'class':'modplaybutton', href: '#'});
player.innerHTML='>'
elem.insert({top: player});
// Start playback
var startPlayback=function(){