Skip to content

Instantly share code, notes, and snippets.


Jonathan Tushman jtushman

View GitHub Profile
View injection.ts
// index.ts
import "reflect-metadata";
import { ApolloServer } from 'apollo-server'
import {AccountResolver} from "./modules/account.resolver";
import * as path from "path";
import {buildSchema} from "type-graphql";
import {createConnection, useContainer} from "typeorm";
import {Container} from "typedi";
View customrepo.ts
export class MemberRepository extends Repository<Member> {
public async findOrCreate(user: User, account: Account) {
// ?? How do I get access to the connection ??
const notebookRepo = connection.getRepository(Notebook);
// do stuff with notebookRepo
// then
jtushman / user.ts
Created May 30, 2019
Best way to add helper methods on TypeORM models
View user.ts
import {
} from 'typeorm';
jtushman /
Last active Jan 3, 2016
Another mutliprocessing Ctr-C (Keyboard Interupt) that is not working -- but seems more elegant
from multiprocessing import Process, Manager, Event
from time import sleep
def f(process_number, shared_array, kb_interupt):
print "starting thread: ", process_number
while not kb_interupt.is_set():
except KeyboardInterrupt:
jtushman /
Created Oct 30, 2013
stashing some thoughts on how I want to port cancan to python
class User: pass
class Project: pass
class Assignment: pass
def current_user():
return User()
def can(action,classes):
raise NotImplementedException
jtushman /
Last active Dec 25, 2015
Randomize your team seating. Ensuring that you are sitting next to two new people you haven't sat next to before. Only works with teams greater than 4
import random
def all_perms(elements):
if len(elements) <=1:
yield elements
for perm in all_perms(elements[1:]):
for i in range(len(elements)):
#nb elements[0:1] works in both string and list contexts
yield perm[:i] + elements[0:1] + perm[i:]
from copy import deepcopy
def dig(hash,*keys):
digs into an dict, if anything along the way is None, then simply return None
So instead of
jtushman / heroku_watcher.rake
Created Jul 7, 2012
Watches heroku router logs and summerizes and notifies
View heroku_watcher.rake
# Excute by the following:
# bundle exec rake GMAIL_PASSWORD=password watch_heroku
task :watch_heroku do
puts "need to set GMAIL_USERNAME and GMAIL_PASSWORD environment variables" unless (ENV['GMAIL_USERNAME'] && ENV['GMAIL_PASSWORD'])
@critical_notified = false
@warning_notified = false
@total_lines = 0
jtushman / watch_mogno.rake
Created Jun 28, 2012
Watches Mongostat and notifies admins via email if lock % is above threashold
View watch_mogno.rake
require 'term/ansicolor'
require 'tlsmail'
task :watch_mongo do
@notified = false
file ='stat_watch')
begin'mongostat') do
View textarea.js
// client/codepad.html
<template name="page">
{{#if any_page_selected}}
{{#with page}}
<textarea id="page_content" class="input-xlarge" style="width: 100%;">{{content}}</textarea>
<div class="form-actions">
<input type="button" class="btn btn-primary" value="Save" />
<button class="btn">Cancel</button>
You can’t perform that action at this time.