Skip to content

Instantly share code, notes, and snippets.

gcloud projects create ${project_id} --organization={organization_id}
gcloud beta billing projects link ${project_id} --billing-account ${account_id}
gcloud projects create ${project_id}
gcloud beta billing projects link ${project_id} --billing-account ${account_id}
def merge(self, intervals):
out = []
for i in sorted(intervals, key=lambda i: i.start):
if out and i.start <= out[-1].end:
out[-1].end = max(out[-1].end, i.end)
else:
out += i,
return out
class Solution:
@nicain
nicain / e0.py
Last active December 30, 2020 06:51
import pandas as pd
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
import bs4
from jinja2 import Template
from collections import OrderedDict
from bokeh.embed import components
@nicain
nicain / clsproperty.py
Created July 1, 2020 17:04
decorator that merges classmethod with property
class clsproperty(object):
"""A data descriptor that sets and returns values
normally and prints a message logging their access.
"""
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
self.fget = fget
self.fset = fset
self.fdel = fdel
if doc is None and fget is not None:
def get_registry_metaclass(registry_name, class_name="MetaRegistry"):
registration_method_name = 'register_class'
def new(meta, name, bases, class_dict):
cls = type.__new__(meta, name, bases, class_dict)
if name not in getattr(meta, registry_name):
getattr(meta, registration_method_name)(getattr(meta, registry_name), cls)
return cls
@nicain
nicain / metaclass_registry.py
Created June 26, 2020 05:09
Class registry via metaclassing
class MetaRegistry(type):
class_registry = {}
def __new__(meta, name, bases, class_dict):
cls = type.__new__(meta, name, bases, class_dict)
if name not in meta.class_registry:
meta.register_class(meta.class_registry, cls)
return cls
@nicain
nicain / .zshrc
Created October 14, 2019 02:33
My .zshrc config
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Anaconda
export PATH=:/Users/nicholasc/anaconda3/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/nicholasc/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
@nicain
nicain / nicain.terminal
Created October 14, 2019 01:58
terminal layout for os x
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGKyxYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKcHCBMZHSQoVSRudWxs1QkKCwwNDg8QERJcTlNDb21wb25lbnRzVU5TUkdCXE5T
Q29sb3JTcGFjZV8QEk5TQ3VzdG9tQ29sb3JTcGFjZVYkY2xhc3NPEB8wLjIxNTY4NjI3
NDUgMC40IDAuNjM1Mjk0MTE3NiAxTxAnMC4xNjc0NzA0NTUyIDAuMzE3Njg1MTg2OSAw
@nicain
nicain / behavior_only.py
Created September 30, 2019 20:32
behavior only NWB file dev
from allensdk.internal.api.mtrain_api import MtrainApi
from allensdk.internal.api.behavior_lims_api import BehaviorLimsApi
from allensdk.brain_observatory.behavior.behavior_session import BehaviorSession
from allensdk.brain_observatory.behavior.behavior_api.behavior_nwb_api import BehaviorNwbApi
bl_api = BehaviorLimsApi()
m_api = MtrainApi()
# Get a session: