Skip to content

Instantly share code, notes, and snippets.

from collections import namedtuple
Measurement = namedtuple('Measurement',
['town', 'time', 'direction', 'speed', 'temperature'])
def format_time(raw):
hour = raw[:2]
minute = raw[2:]
return f'{hour}:{minute}'
@z2s8
z2s8 / error1.py
Last active March 27, 2017 17:54
statscache plugin outputs
[2017-03-27 19:17:12][ fedmsg ERROR] Failed to load plugin from EntryPoint.parse('newy = statscache_plugins.new_statscache_plugin:Plugin')
Traceback (most recent call last):
File "/var/tmp/stats/statscache/statscache/utils.py", line 95, in init_plugins
entry_object = entry_point.load()
File "/var/tmp/stats/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/var/tmp/stats/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/var/tmp/stats/statscache_plugins/statscache_plugins/new_statscache_plugin.py", line 6, in <module>
class Model(BaseModel):

Keybase proof

I hereby claim:

  • I am z2s8 on github.
  • I am z2s8 (https://keybase.io/z2s8) on keybase.
  • I have a public key whose fingerprint is 282A 1D44 ABEF 174A 6925 A3BA 20C7 5F00 C13C 1D74

To claim this, I am signing this object:

@z2s8
z2s8 / after.txt
Last active November 1, 2016 00:34
Rubocop output
$ rubocop
Inspecting 41 files
............C.................C..........
Offenses:
test/api/v1/routes/exercises_test.rb:93:20: C: Always use raise to signal exceptions.
error = proc { fail Exception.new("failing hard") }
^^^^
api/services/exercism_io.rb:53:7: C: Always use raise to signal exceptions.
@z2s8
z2s8 / dr.rb
Created June 6, 2016 23:27
dumb repl in 20 lines of ruby.. todo: wrap exec maybe to crosslang?
#!/usr/bin/env ruby
def save_line(line)
open('repldata', 'a') do |repldata|
repldata.puts "puts %s(> #{line.rstrip})"
repldata.puts "print('= ')"
repldata.puts "puts(#{line})"
end
end
Python 3.5.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
a=set()
=> None
a.add(8)
=> None
b=set([4])
=> None
a
@z2s8
z2s8 / ssl.cr
Last active April 9, 2016 19:00
verify github webhook with Crystal-lang
# based on developer.github.com/webhooks/securing
require "openssl"
require "openssl/hmac"
# constant time string comparison between fixed length strings
# forked from github.com/rack/rack, modified to work with crystal
def secure_compare(a, b)
return false unless a.bytesize == b.bytesize
@z2s8
z2s8 / prime.rb
Created March 3, 2016 01:21
Prime finder in ruby
NUMBER_OF_PRIMES = 150000
primes = [2]
test_number = 2
primes_found = 0
while primes_found < NUMBER_OF_PRIMES
test_primitiveness = true
i = 0
while (primes.size > i && primes[i] <= Math.sqrt(test_number) && test_primitiveness)
if test_number % primes[i] == 0
@z2s8
z2s8 / prime.cr
Created March 3, 2016 01:13
Prime finder in crystal-lang
require "math"
NUMBER_OF_PRIMES = 1500000
primes = [2]
test_number = 2
primes_found = 0
while primes_found < NUMBER_OF_PRIMES
test_primitiveness = true
i = 0
@z2s8
z2s8 / valasztas.py
Created February 24, 2016 23:47
2013 majus emelt prog
from collections import namedtuple
from decimal import Decimal
def reszfeladat(n): # sorszam kiirasa
print('{}. feladat'.format(n))
def kepviselo_ki(kepviselo): # kimenet formazas osszes tulajdonsagra
part = kepviselo.part if kepviselo.part != '-' else 'fuggetlen'
return '{} {} {} {}'.format(kepviselo.kerulet, kepviselo.v_nev,
kepviselo.u_nev, part)