Skip to content

Instantly share code, notes, and snippets.

View joonty's full-sized avatar

Jonathan Cairns joonty

View GitHub Profile
@joonty
joonty / threaded-vim-server.py
Created October 7, 2013 15:11
Background thread based socket server for vim
import sys
import socket
import select
import Queue
import threading
import time
import vim
import os
class LogError(Exception):
@joonty
joonty / vim-socket-server.py
Last active June 9, 2020 15:04
A vim-friendly, thread and queue based socket server written in python
import sys
import socket
import select
import Queue
import threading
import time
class EchoServer(threading.Thread):
def __init__(self, host, port, message_queue, output_queue):
self.__message_queue = message_queue
@joonty
joonty / each_with_object.rb
Last active December 22, 2015 08:58
Strange behaviour of array concatenation and each_with_object
def flatten_keys(hsh, keys)
keys.each_with_object([]) { |k, result|
result += hsh[k]
}
end
def flatten_keys_each(hsh, keys)
result = []
keys.each { |k|
result += hsh[k]
@joonty
joonty / php-xdebug
Created August 14, 2013 11:47
Xdebug php wrapper
#!/bin/bash
export XDEBUG_CONFIG="idekey=xdebug"
/usr/bin/php "$@"
@joonty
joonty / word_game.rb
Created July 30, 2013 13:28
Word game IRC bot, as a Cinch plugin
require 'cinch'
class Cinch::Plugins::WordGame
include Cinch::Plugin
match(/word start/, method: :start)
def start(m)
@word = DictionaryWord.new("/etc/dictionaries-common/words")
@guesses = 0
m.reply "Starting a new word game. Make a guess."
@joonty
joonty / gist:6029349
Last active December 19, 2015 22:39
Cycle through an array during creation of another array .
options = [:hit, :miss, :unknown].cycle
Array.new(10) { Array.new(10) { |v| options.next } }
@joonty
joonty / gist:6000969
Created July 15, 2013 15:42
Test for two threads accessing the same array, one thread iterating and the other appending.
iterations = 0
payloads = (1..1000).to_a
threads = []
threads << Thread.new do
200.times do
add_num = rand(1000..2000)
puts "\nAdding #{add_num} to payload"
payloads << add_num
end
@joonty
joonty / gist:5757619
Created June 11, 2013 15:03
Output of `rspec` for vdebug integration test
:VdebugOpt
setting debug_file
behaves like a vdebug option
the resulting option value
should == "path/to/file.log"
setting debug_file_level
behaves like a vdebug option
the resulting option value
should == "2"
setting debug_window_level
@joonty
joonty / gist:5619534
Created May 21, 2013 12:47
Output from `tork-remote tork-engine`
["echo",["run_test_files",["spec/conductor_spec.rb","spec/observer_set_spec.rb","spec/event_spec.rb","spec
/test_event_spec.rb","spec/echo_event_spec.rb","spec/reader_spec.rb","spec/status_change_event_spec.rb","s
pec/pass_or_fail_event_spec.rb","spec/event_parser_spec.rb","spec/listener_spec.rb"]]]
["echo",["test","spec/conductor_spec.rb",[]]]
["echo",["test","spec/conductor_spec.rb",[],"spec/conductor_spec.rb.log",1]]
["test","spec/conductor_spec.rb",[],"spec/conductor_spec.rb.log",1]
["echo",["test","spec/observer_set_spec.rb",[]]]
["echo",["test","spec/observer_set_spec.rb",[],"spec/observer_set_spec.rb.log",0]]
["test","spec/observer_set_spec.rb",[],"spec/observer_set_spec.rb.log",0]
["echo",["test","spec/event_spec.rb",[]]]
@joonty
joonty / client-7.1.0.patch
Last active July 4, 2020 13:45
Patch for client.py, part of the Komodo Python remote debugger. Fixes an exception being raised when "eval" is used, for versions 7.1.0 and 8.5.0.
3249,3250c3249
< _eval_optlist = [['i','transaction_id', int, 1, -1, None],
< ['l','length', int, 1, 0, None]]
---
> _eval_optlist = [['i','transaction_id', int, 1, -1, None]]
3252c3251
< (tid, data_length, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
---
> (tid, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
3268,3269c3267,3268