Skip to content

Instantly share code, notes, and snippets.

View edcrypt's full-sized avatar

Eduardo de Oliveira Padoan edcrypt

View GitHub Profile
@edcrypt
edcrypt / blocRope.st
Last active September 6, 2019 20:14
Bloc's Rope data structure usage
| text |
[
EpMonitor current disable.
Metacello new
baseline: 'Bloc';
repository: 'github://feenkcom/Bloc/src';
load: 'Bloc-Text-Rope'
] ensure: [ EpMonitor current enable ].
Object subclass: #Artist
instanceVariableNames: 'tracks'
methods for: 'initialising'
initialize
tracks := OrderedCollection new.
^self
methods for: 'checking'
invariant
^(tracks isMemberOf: OrderedCollection) and: [
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
| seq |
seq := OrderedCollection with: 1 with: 1.
1 to: 1000 do: [ :n |
seq add: (seq last * ((4 * n) + 2)) / (n + 2)].
seq
@edcrypt
edcrypt / progressBar.st
Created December 28, 2018 21:22
Show a progress bar based on an interval on Pharo
myColl := 1 to: 20.
[ :job |
myColl
do: [ :e |
job
progress: e / myColl size;
title: 'waiting ' , e asString.
(Delay forSeconds: 0.5) wait ] ] asJob run
@edcrypt
edcrypt / Webdev.st
Created December 1, 2018 03:37
Install Seaside web development stuff on Pharo7
Transcript clear; cr; show: 'Updating Zinc...'; cr.
Metacello new
repository: 'github://svenvc/zinc/repository';
baseline: 'ZincHTTPComponents';
load.
Transcript cr; show: 'Installing Seaside...'; cr.
Metacello new
@edcrypt
edcrypt / coro_account.py
Created August 30, 2017 21:19
Basic message sending using generators as corotines
def Account(balance):
ret = None
while True:
# receive message
selector, *args = yield ret
# dispatch
if selector == 'withdraw':
@edcrypt
edcrypt / entropic.py
Created July 17, 2017 20:34
Entropy Harvester
import entropy # pip install entropy
from collections import namedtuple
MIN_ENTROPY = 0.5
MIN_LENGTH = 140
S = namedtuple('S', 'text entropy')
def read_entropic(prompt='', min_entropy=MIN_ENTROPY, min_length=MIN_LENGTH):
s = ''
@edcrypt
edcrypt / tokenizer.py
Last active June 24, 2017 22:20
Quick tokenizer to showcase some py3.6 features
# flake8: noqa
import regex
import collections
from typing import NamedTuple
class OrderedClassMembers(type):
@classmethod
@edcrypt
edcrypt / attrs.hy
Last active April 26, 2017 20:27
Helper macro for attrs lib on Hy
; -*- mode: lisp; mode: paredit -*-
(defmacro defattrs [klass-name
&optional [super-klasses []] [options []] [attrs []]
&rest body]
`(do
(import attr)
(with-decorator ~(if options `(attr.s ~@options) 'attr.s)
(defclass ~klass-name ~super-klasses
~(list (interleave