This file contains 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
# monkey-patch django loaddata to ignore foreign key checks | |
from django.core.management.commands.loaddata import Command | |
from django.db import connections, DEFAULT_DB_ALIAS | |
def uses_mysql(connection): | |
return 'mysql' in connection.settings_dict['ENGINE'] | |
_old_handle = Command.handle | |
def _foreign_key_ignoring_handle(self, *fixture_labels, **options): | |
"""Wrap the the stock loaddata to ignore foreign key checks so we can load | |
circular references from fixtures. | |
This file contains 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 csv | |
import os | |
STORING_TO_CSV = False | |
if 'STORE_TO_CSV' in os.environ: | |
facilities_csv = csv.writer(open('thd_facilities.csv', 'w')) | |
inspections_csv = csv.writer(open('thd_inspections.csv', 'w')) | |
STORING_TO_CSV = True | |
print "Storing to CSV" |
This file contains 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
const email_detector_ruleset = ruleset([ | |
// Inputs that could be email fields: | |
rule(dom("input[type=text],input[type=\"\"],input:not([type])").when(isVisible), type("email")), | |
// Look for exact matches of "email"-like keywords in some attributes of the <input> | |
rule( | |
type("email"), | |
score(fnode => attrsMatch(fnode.element, ["id", "name", "autocomplete"], emailRegexMatchLine)), | |
{name: "inputAttrsMatchEmailExactly"} | |
), |
This file contains 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
const enLocaleArgs = { | |
hash: args.hash, data: {root: {req: {supportedLocales: ["en"]} } }, | |
}; | |
const bannerOpeningDivDataset = microSurveyResponseIds.reduce((datasetStr, id) => { | |
datasetStr + `data-${id}-translated="${getString(id, args)}" data-${id}-english="${getString(id, enLocaleArgs)}" `; | |
console.log(`datasetStr: ${datasetStr}`); | |
return datasetStr; | |
}); |
This file contains 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 time_if_enabled(func): | |
def timing_decorator(name): | |
def func_wrapper(name): | |
ctx_manager = (request.timings(name) if settings.STATSD_ENABLED | |
else contextlib.suppress()) | |
with ctx_manager: | |
func() | |
return func_wrapper | |
return timing_decorator |
This file contains 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 requests | |
from django.apps import AppConfig | |
from django.conf import settings | |
class PrivateRelayConfig(AppConfig): | |
name = 'privaterelay' | |
def __init__(self, app_name, app_module): |
This file contains 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 requests | |
from jwt import jwk_from_dict | |
from django.apps import AppConfig | |
from django.conf import settings | |
class PrivateRelayConfig(AppConfig): | |
name = 'privaterelay' |
This file contains 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
logger.info({ | |
'event_type': 'email_relay', | |
'relay_address_id': relay_address.id, | |
'relay_address': sha256(local_portion.encode('utf-8')).hexdigest(), | |
'real_address': sha256( | |
relay_address.user.email.encode('utf-8') | |
).hexdigest(), | |
}) |
This file contains 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
if (AppConstants.NODE_ENV === "dev") { | |
knex.on("query", async (queryData) => { | |
debugger; | |
console.log(queryData); | |
}); | |
knex.on("query-response", async (response, obj, builder) => { | |
debugger; | |
const explainSql = `EXPLAIN VERBOSE ${builder}`; | |
const res = await knex.raw(explainSql); | |
}); |
NewerOlder