Skip to content

Instantly share code, notes, and snippets.

Avatar

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
@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
Best way to add helper methods on TypeORM models
View user.ts
import {
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
BeforeInsert,
OneToOne,
Connection
} from 'typeorm';
@jtushman
jtushman / multi.py
Last active Jan 3, 2016
Another mutliprocessing Ctr-C (Keyboard Interupt) that is not working -- but seems more elegant
View multi.py
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 Oct 30, 2013
stashing some thoughts on how I want to port cancan to python
View pycan.py
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 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
View random_seating_order.py
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:]
View dig.py
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 Jul 7, 2012
Watches heroku router logs and summerizes and notifies
View heroku_watcher.rake
# 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 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 = Tempfile.new('stat_watch')
begin
Thread.new('mongostat') do
View textarea.js
// 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>
You can’t perform that action at this time.