diff --git a/scratch/db.py b/scratch/db.py deleted file mode 100644 index 294791d..0000000 --- a/scratch/db.py +++ /dev/null @@ -1,13 +0,0 @@ -from swh.storage import db - -# ok! -with db.connect ('dbname=softwareheritage-dev') as db_conn: - with db_conn.cursor() as cur: - cur.execute("insert into swh.origin(type, url) values ('git', 'https://github.com/ardumont/dot-files2') returning id") - r = cur.fetchone() - print(r) - -# ok! -with db.connect ('dbname=softwareheritage-dev') as db_conn: - r = db.insert(db_conn, "insert into swh.origin(type, url) values ('git', 'https://github.com/ardumont/dot-files2') returning id") - print(r) diff --git a/scratch/futures.py b/scratch/futures.py deleted file mode 100755 index c3914bd..0000000 --- a/scratch/futures.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -# source: https://docs.python.org/3/library/concurrent.futures.html - -import concurrent.futures -import math - -PRIMES = [ - 112272535095293, - 112582705942171, - 112272535095293, - 115280095190773, - 115797848077099, - 1099726899285419, - 112272535095293, - 112582705942171, - 112272535095293, - 115280095190773, - 115797848077099, - 1099726899285419, - 112272535095293, - 112582705942171, - 112272535095293, - 115280095190773, - 115797848077099, - 1099726899285419, - 112272535095293, - 112582705942171, - 112272535095293, - 115280095190773, - 115797848077099, - 1099726899285419, -] - -def is_prime(n): - if n % 2 == 0: - return False - - sqrt_n = int(math.floor(math.sqrt(n))) - for i in range(3, sqrt_n + 1, 2): - if n % i == 0: - return False - return True - -def main(): - with concurrent.futures.ProcessPoolExecutor() as executor: - for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)): - print('%d is prime: %s' % (number, prime)) - - # sequential code - # for number, prime in zip(PRIMES, map(is_prime, PRIMES)): - # print('%d is prime: %s' % (number, prime)) - -if __name__ == '__main__': - main() diff --git a/scratch/git_visit.py b/scratch/git_visit.py deleted file mode 100644 index 062ebc0..0000000 --- a/scratch/git_visit.py +++ /dev/null @@ -1,47 +0,0 @@ -# (* OCaml: non tail-recursive version *) - -# let rec visit obj = -# if not (is_in_cache obj) then begin -# List.iter visit (get_parents obj); -# store_object obj -# end - -# let _ = visit root_obj - - -# (* OCaml: (almost) tail-recursive version *) - -# let visit obj = -# let rec aux visit_todo store_todo = -# match visit_todo with -# | [] -> store_todo -# | obj :: rest -> -# if not (is_in_cache obj) then -# let parents = get_parents obj in -# (* "@" is not tail-rec in OCaml (length of 1st arg.), but we don't -# care here, as equivalent operators might be tail-rec in other -# languages. To be tail-rec in OCaml we would need List.rev_append -# here, and to do reverse gymnastic elsewhere. *) -# aux (rest @ parents) (obj :: store_todo) -# in -# let objects_to_store = aux [obj] [] in -# List.iter store_object objects_to_store - -# let _ = visit root_obj - -from collections import deque - -def visit(root_obj, cache, store): - - to_visit = deque([root_obj]) # FIFO - to_store = deque() # LIFO - - while to_visit: # 1st pass: visit top-down, use cache, collect to_store - obj = to_visit.popleft() # extract from beginning (left) - if obj not in cache: - to_visit.extend(obj.parents) # append to end (right) - to_store.append(obj) - - while to_store: # 2nd pass: store objects bottom-up - obj = to_store.pop() - store.add(obj) diff --git a/scratch/http.py b/scratch/http.py deleted file mode 100755 index 31dc93e..0000000 --- a/scratch/http.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -import requests - -response = requests.get('http://localhost:5000/commits/1') - -print(response) diff --git a/scratch/retry-tryout.py b/scratch/retry-tryout.py deleted file mode 100755 index b67fabd..0000000 --- a/scratch/retry-tryout.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python3 - -import random -from retrying import retry - - -@retry -def pick_one(): - r = random.randint(0, 10) - print(r) - if r != 1: - raise Exception("1 was not picked") - - -if __name__ == '__main__': - pick_one() diff --git a/scratch/scratch-swh-api.py b/scratch/scratch-swh-api.py deleted file mode 100644 index 7346804..0000000 --- a/scratch/scratch-swh-api.py +++ /dev/null @@ -1,5 +0,0 @@ -from swh.storage import store -from swh.protocols import serial -from swh.client import http - -r = http.put('http://localhost:5000', store.Type.origin, {'url': 'https://github.com/swh/good.git', 'type': git})