Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️‍♂️
Working on secret stuff.

Andrew Tremblay andrewtremblay

🕵️‍♂️
Working on secret stuff.
View GitHub Profile
@andrewtremblay
andrewtremblay / use-toggle.ts
Created Jul 26, 2022 — forked from fnky/use-toggle.ts
Simple toggle hook using useReducer w/ types for reducer with optional action.
View use-toggle.ts
import React from "react";
type ReducerWithOptionalAction<S> = (prevState: S, action?: S) => S;
type ReducerStateWithOptionalAction<S> = React.ReducerState<ReducerWithOptionalAction<S>>;
type DispatchWithOptionalAction<S> = React.Dispatch<S> & React.DispatchWithoutAction;
type ReducerValueWithOptionalAction<S> = [
ReducerStateWithOptionalAction<S>,
React.DispatchWithOptionalAction<S>,
];
View calculate_secret_santas.py
import csv
import random
input_spreadsheet_name = 'secret_santas_input.csv'
secret_spreadsheet_name = 'secret_santa_assigments.csv'
# recursive match making
def make_matches(remaining_people, next_santa=None, original_santa=None, processed_people={}):
if len(remaining_people) is 0:
@andrewtremblay
andrewtremblay / README.md
Last active Sep 30, 2019
Smart Commit git hooks and scripts
View README.md
View blog_0001
# SVG Portraits in React Native
## Using the ART Library
https://upload.wikimedia.org/wikipedia/commons/0/01/Stylized_Mona_Lisa.svg
Vector graphics are the most efficient way to display your images at any resolution. And when it comes to vector graphics, svgs are the de-facto file standard.
https://github.com/facebook/react-native/tree/master/Libraries/ART
https://github.com/facebook/react-native/blob/master/Libraries/ART/ARTSurfaceView.m#L48
@andrewtremblay
andrewtremblay / exported_svg_from_ai.svg
Last active Feb 25, 2018
SVG Tools Review 2018-02-25
View exported_svg_from_ai.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andrewtremblay
andrewtremblay / common_model_classes_in_use.py
Last active Feb 23, 2018
An example of how to use common model classes.
View common_model_classes_in_use.py
# import CommonModel, CommonSerializer, CommonViewSet
# from https://gist.github.com/andrewtremblay/94c485f816f3095d7e86668b97b1a668
class Note(CommonModel):
"""Note content, written by a user."""
text_body = models.TextField(default="")
class NoteSerializer(CommonSerializer):
"""Serialize requests for Text Content."""
@andrewtremblay
andrewtremblay / common_model_classes.py
Last active Feb 23, 2018
Django classes that help you create a common model for your database.
View common_model_classes.py
from django.db import models
from django.conf import settings
from rest_framework import viewsets, serializers
class CommonModel(models.Model):
"""Common fields that are shared among all models."""
created_by = models.ForeignKey(settings.AUTH_USER_MODEL,
editable=False, related_name="+")
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL,
@andrewtremblay
andrewtremblay / scrub_ghost.py
Last active Dec 11, 2017
Ghost export file scrubbing script
View scrub_ghost.py
# Python 2.7.10
# usage:
# python scrub_ghost.py my_ghost_export.json
#
# outputs to my_ghost_export_scrubbed.json
# takes a ghost export file and prepares the posts for import of into wp
# (see https://plugins.trac.wordpress.org/browser/import-from-ghost?order=name#trunk)
# removes the following unneeded information:
# draft posts
View 1000_words.txt
the
of
to
and
a
in
is
it
you
that
View memoized_anagram_solver.py
import nltk
import functools
def memoize_anagrams(obj):
cache = obj.cache = {}
jumbled_args_index = 0
@functools.wraps(obj)
def memoizer(*args, **kwargs):
if args[jumbled_args_index] not in cache:
cache[args[jumbled_args_index]] = obj(*args, **kwargs)