Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:

luke crouch groovecoder

:shipit:
View GitHub Profile
View email_detector.js
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"}
),
View hbs-helpers.js
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;
});
View views.py
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
View apps.py
import requests
from django.apps import AppConfig
from django.conf import settings
class PrivateRelayConfig(AppConfig):
name = 'privaterelay'
def __init__(self, app_name, app_module):
View apps.py
import requests
from jwt import jwk_from_dict
from django.apps import AppConfig
from django.conf import settings
class PrivateRelayConfig(AppConfig):
name = 'privaterelay'
View views.py
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(),
})
View ip_monitor.hbs
<span class="browser-not-required">
Firefox browser not required for a Firefox Account. You may receive info about Mozilla services.
</span>
View DB.js
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);
});
View index.js
const crypto = require("crypto");
const express = require("express");
const app = express();
const port = 3000;
app.get("/browser/oauth/state", (req, res) => {
console.log("state token request");
const state = crypto.randomBytes(32).toString("hex");
res.status(201).json({
View middleware.js
// Helps handle errors for all async route controllers
// See https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
function asyncMiddleware (fn) {
return (req, res, next) => {
Promise.resolve(fn(req, res, next)).catch(next);
};
}