Skip to content

Instantly share code, notes, and snippets.

@padde
padde / array.rb
Last active December 14, 2015 13:59
Array#each_with_position
class Array
class Position
attr_accessor :idx, :max
def initialize arr
self.max = arr.size
end
def pos
idx + 1
@padde
padde / array.rb
Last active December 14, 2015 14:08
Array#each_with_position (cached) Useful if you call the pos methods often.
class Array
class Position
def initialize ary
@pos = 1
@max = ary.size
@cache = Hash.new
end
def advance
@pos += 1
@padde
padde / enumerable.rb
Last active December 14, 2015 14:08
Enumerable#each_with_position (with other? and other{ ... })
module Enumerable
class Position
def initialize ary
@pos = 1
@max = ary.size
@cache = Hash.new
@warn_other = false
end
def advance
@padde
padde / gist:5106440
Created March 7, 2013 08:26
delimitMate Report
delimitMate Report
==================
* Options: ( ) default, (g) global, (b) buffer
( ) delimitMate_apostrophes = ''
( ) delimitMate_autoclose = 1
( ) delimitMate_balance_matchpairs = 0
( ) delimitMate_eol_marker = ''
( ) delimitMate_excluded_ft = ''
<div id="image" class="image textbox ">
<div class="">
<img src="img.jpg" alt="" original-title="">
</div>
</div>
@padde
padde / benchmark.rb
Last active December 16, 2015 12:19
require 'fruity'
compare do
rubylovely {
a3 = [["a", "b"], ["a","c"], ["b","c"], ["b", "a"], ["c","b"],["b", "a"]]
a3.each {|x| a3.delete(x.reverse) if a3.include? x.reverse}
}
padde {
a3 = [["a", "b"], ["a","c"], ["b","c"], ["b", "a"], ["c","b"],["b", "a"]]
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="Magento" targetNamespace="urn:Magento">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
<complexType name="FixedArray">
<complexContent>
<restriction base="soapenc:Array">
<wsdl:definitions xmlns:ns2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="Magento" targetNamespace="urn:Magento">
<wsdl:types>
<xs:schema targetNamespace="urn:Magento">
<xs:attribute name="root">
<xs:annotation>
<xs:documentation>
'root' can be used to distinguish serialization roots from other
elements that are present in a serialization but are not roots of
a serialized value graph
</xs:documentation>
@padde
padde / openvpn.md
Last active April 30, 2018 17:11
OpenVPN on Ubuntu 12.10 at DigitalOcean

OpenVPN on Ubuntu 12.10 at DigitalOcean

Install OpenVPN

sudo apt-get install openvpn

Generate Server Certificates

sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 /etc/openvpn/easy-rsa2

cd /etc/openvpn/easy-rsa2

@padde
padde / quine.rb
Last active December 20, 2015 07:49
A little Quine
puts a=[<<-X*2,?X]
puts a=[<<-X*2,?X]
X