Skip to content

Instantly share code, notes, and snippets.

View jtushman's full-sized avatar

Jonathan Tushman jtushman

View GitHub Profile
// 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";
@EntityRepository(Member)
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
jtushman / user.ts
Created May 30, 2019 15:15
Best way to add helper methods on TypeORM models
import {
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
BeforeInsert,
OneToOne,
Connection
} from 'typeorm';
@jtushman
jtushman / multi.py
Last active January 3, 2016 04:59
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():
try:
shared_array.append(process_number)
sleep(3)
except KeyboardInterrupt:
@jtushman
jtushman / pycan.py
Created October 30, 2013 11:23
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
jtushman / random_seating_order.py
Last active December 25, 2015 05:58
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
else:
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:]
@jtushman
jtushman / dig.py
Last active December 14, 2015 09:49
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
entry['bids']['maxCpm']['amount']['microAmount']
@jtushman
jtushman / heroku_watcher.rake
Created July 7, 2012 00:00
Watches heroku router logs and summerizes and notifies
# Excute by the following:
# bundle exec rake GMAIL_USERNAME=name@example.com 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
jtushman / watch_mogno.rake
Created June 28, 2012 20:10
Watches Mongostat and notifies admins via email if lock % is above threashold
require 'term/ansicolor'
require 'tlsmail'
task :watch_mongo do
@notified = false
file = Tempfile.new('stat_watch')
begin
Thread.new('mongostat') do
@jtushman
jtushman / textarea.js
Created May 21, 2012 18:00
meteor snipit
// client/codepad.html
<template name="page">
{{#if any_page_selected}}
{{#with page}}
<h2>{{name}}</h2>
<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>
</div>