Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bewt85 on github.
  • I am bewt85 (https://keybase.io/bewt85) on keybase.
  • I have a public key ASDtU4pLFN9jmDiQw7znCgeoI8rbIDXM7LRmbAvtK8AxMAo

To claim this, I am signing this object:

@bewt85
bewt85 / SequenceArchives.py
Created March 7, 2019 18:04
Some code from a project downloading data from ENA
import hashlib
import json
import logging
import os
import re
import requests
import subprocess
import sys
import time
import urllib
@bewt85
bewt85 / README.md
Last active July 8, 2023 08:09
here-here - what did I run here

here-here

here-here is like history but it saves the time you ran a command and the directory you were in when you ran it. Running here tells you all the commands you ran in this directory even if you were on a different server.

I commonly wonder how I made a file (and maybe why). Sometimes I try looking in my history (using the history command). This makes that easier by clearing out some of the noise.

Installation

const { Readable } = require('stream');
const logger = require("debug");
const _ = require("lodash");
const whenHttpRequestComplete = new Promise(resolve => setTimeout(resolve, _.random(100, 1000)));
class SlowNumberSource extends Readable {
constructor(options={}) {
super(options);
this.getNext = this.buildNext(1);
@bewt85
bewt85 / write_foo.py
Created April 28, 2015 09:39
Python dodgy file handle modes
with open('foo', 'w') as foo:
foo.write("bar\n") # writes bar
with open('foo', 'wa') as foo:
foo.write("baz\n") # writes baz, removes bar
with open('foo', 'what will this do?') as foo:
foo.write("nonsense\n") # removes bar, writes nonsense!
with open('foo', 'something else') as foo:
@bewt85
bewt85 / Futures.py
Created March 26, 2015 01:24
A mix of scala's Future and Try in Python
import gevent
class Try(object):
def __init__(self, result):
self.result = result
class Success(Try):
def __repr__(self):
return "<Success '%s'>" % self.result
@bewt85
bewt85 / directory_structure.txt
Last active August 29, 2015 14:17
mocking os.path.isdir
.
├── bar
├── foo
├── scripts
│   ├── foobar.py
│   └── __init__.py
└── tests
├── foobar_test.py
└── __init__.py
@bewt85
bewt85 / pullAllSubmodules.sh
Last active August 29, 2015 14:02
Script to pull latest version of submodules
#!/bin/bash
START_DIR=$(pwd)
for dir in $(find . -name ".git" -type d); do
cd $(echo $dir | sed 's/\/.git$//') && git checkout master && git pull && cd $START_DIR;
done
git status
@bewt85
bewt85 / splitGitDirs.sh
Created June 8, 2014 19:12
Script to help split a project into sub-modules
#!/bin/bash
set -ex
ROOT_DIR=$(cd $(dirname $1); pwd)/$(basename $1)
START_DIR=$(pwd)
[[ -d ${START_DIR}/splits ]] || mkdir ${START_DIR}/splits
for subProject in $(find $ROOT_DIR -mindepth 1 -maxdepth 1 -type d | grep -v git); do
@bewt85
bewt85 / pseudoRandom.py
Created June 8, 2014 16:41
Creates a file which appears random but is actually deterministic
#!/usr/bin/env python
from hashlib import md5
import argparse, os
parser = argparse.ArgumentParser(description="Makes pseudo-random but deterministic files of ascii text")
parser.add_argument('output_file', help="Location of output file")
parser.add_argument('size', nargs='?', default=1024, type=int, help="Size in bytes of output file")
parser.add_argument('seed', nargs='?', default=None, help="A seed value to differentiate output files")
args = parser.parse_args()