This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from flask import Response, stream_with_context | |
def render_as_json(generator_creating_function): | |
""" Decorator to render JSON from generator-creating functions | |
""" | |
def wrapper(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en-us"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Trivia</title> | |
</head> | |
<body> | |
<div id="timer"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en-us"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hangman</title> | |
</head> | |
<body> | |
<div id="scoreboard"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'formula' | |
class Vim < Formula | |
homepage 'http://www.vim.org/' | |
url 'https://vim.googlecode.com/hg/', :revision => '6c318419e331' | |
version '7.3.515' | |
def features; %w(tiny small normal big huge) end | |
def interp; %w(lua mzscheme perl python python3 tcl ruby) end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import requests | |
from copy import copy | |
# To run try this out, run --> `python coroutines.py` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def find_venv_dependency(name): | |
if not hasattr(sys, 'real_prefix'): | |
return # venv not activated | |
venv = sys.prefix.split('/')[len(os.getcwd().split('/'))] | |
for root, dirs, files in os.walk(venv): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_dicts_arrs(d1, d2): | |
for k,v in d2.items(): | |
if k in d1.keys(): | |
d1[k] = d1[k] + d2[k] | |
else: | |
d1.update({k:v}) | |
return d1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_dict(d, term, nests=[]): | |
def last(array): | |
return array[-1] | |
''' | |
breadth-first search a dictionary | |
''' | |
presence = None | |
nests_at_this_level = [d.get(key) for key in d.keys() if type(d.get(key)).__name__ == 'dict'] | |
lists_with_nests = [d.get(key) for key in d.keys() | |
if type(d.get(key)).__name__ == 'list' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Associator | |
attr_reader :rails_app_dir, :associations | |
ASSOCIATION_TYPES = [ | |
"belongs_to", | |
"has_one", | |
"has_many", | |
"has_and_belongs_to_many" | |
] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepend_str_to_hash_value(hash, subhashes=[], **kwargs) | |
keys = hash.keys | |
until keys.count == 0 | |
key = keys.pop | |
hash[key] = kwargs[:str] + hash[key] if (kwargs[:keys_like] != "" && hash[key] != kwargs[:vals_unlike] && key.to_s.include?(kwargs[:keys_like].to_s) && [String, Fixnum].include?(hash[key].class)) | |
subhashes << hash[key] if hash[key].class == Hash | |
end | |
return subhashes.empty? ? true : prepend_str_to_hash_value(subhashes.pop, subhashes, **kwargs) | |
end |
NewerOlder