Skip to content

Instantly share code, notes, and snippets.

View heftig's full-sized avatar
🦄
Horsing around

Jan Alexander Steffens heftig

🦄
Horsing around
View GitHub Profile
import os
from gi.repository import GLib, Gio
# ---
def handle_lock():
print("Lock")
def handle_unlock():
print("Unlock")
import os
from gi.repository import GLib, Gio
# ---
def handle_lock():
print("Lock")
def handle_unlock():
print("Unlock")
filename="foobar"
File.open(filename, "r") do |fr|
File.open(filename + "~nop", "w") do |fw|
fr.each_line do |line|
fw.write line.gsub(".", "")
end
File.rename(filename + "~nop", filename)
end
end
require 'socket'
sockpath = "/tmp/foosock"
if ARGV.first == "server"
socket = UNIXServer.new sockpath
begin
while client_sock = socket.accept do
Thread.start do
puts "New connection"
class PokerGame
include Enumerable
include Comparable
attr_reader :hands, :deck
RANKS = %w{ 2 3 4 5 6 7 8 9 T J Q K A }
SUITS = %w{ S H D C }
def initialize(hands, cards)
@deck = RANKS.product(SUITS).map(&:join)
def events_all_accounts(time)
self.accounts.flat_map do |account|
account.events.send(time, account.now).where(:client_id => self.id)
end.uniq.sort_by { |a| a.start_time }
end
private :events_all_accounts
# all upcoming events for a client
def future_events_all_accounts
events_all_accounts(:in_future)
primes = [2]
current_number = 3
while primes.length < 10
primes.push(current_number) unless primes.any? { |p| current_number % p == 0 }
current_number += 2
end
puts primes
device_from_filename() {
# canonicalize filename
local realpath="$(readlink -e "$1")"
[[ ! -e $realpath ]] && return 1
# read /etc/mtab into associative array mtab
local -A mtab
local device mountpoint rest
while read device mountpoint rest; do
TOKEN_PROCESSORS = []
def processor(regex, &proc)
TOKEN_PROCESSORS << [regex, proc]
end
# Finds a word followed by any value
processor /\A([A-z]\w*)\s*([^\n]*)?/ do |chunk, matches|
matches[0].upcase!
attr_writer :full_name
def full_name
@full_name || "#{@first_name} #{@last_name}"
end