Skip to content

Instantly share code, notes, and snippets.

function hideable(instance, isHidden) {
const HideableComponent = React.createClass({
render() {
if (isHidden) {
return null;
}
return React.cloneElement(instance, this.props);
}
@cdosborn
cdosborn / README.md
Last active June 9, 2017 21:27
A side by side comparison of a component before/after refactor

ResourceHistoryMaster.jsx

I was working on a refactor, I thought I would create this gist as a way to show some patterns that I like.

The rewritten file is ResourceHistoryMaster-AFTER.jsx. I think it's worth looking over the original file, before looking at the new one.

The rewritten file is heavily commented.

A view of the Atmosphere service rendering a user's requests

@cdosborn
cdosborn / searcher.ts
Last active February 5, 2024 18:38 — forked from sod/giganticString.js
A modified interface to the SOD search algorithm ;)
import escapeStringRegexp from "escape-string-regexp";
import bs from "binary-search";
// interface SearchFunc<T> {
// (needle?: string, maxResults: number): T[]
// }
// search = searcher(d => [d.name, d.age], [{name:"a", age:4}, ...])
// search("4") -> {name:"a", age:4}
const searcher = <T>(
@cdosborn
cdosborn / index.js
Created January 31, 2018 19:04
Javascript comparsions: Is variable a number?
let testCases = [
['""', "", false],
['"\\t"', "\t", false],
['" "', " ", false],
['"Infinity"', "Infinity", false],
['"123abc"', "123abc", false],
['"abc123"', "abc123", false],
['"+123"', "+123", false],
['"1."', "1.", true],
['"."', ".", false],
@cdosborn
cdosborn / gist:79f50340ab609656dd4481c02cadfcc0
Last active February 17, 2018 04:07
Puzzling behavior of python's repr and __repr__
If you open up a python shell and execute the following code,
class Foo:
def __repr__(self):
return u'\xe0'
repr(Foo())
The last line will throw the following exception:
@cdosborn
cdosborn / gist:35af1d2b91604f4d311c3efc8acf3563
Last active March 8, 2018 05:16
The 1 minute guide to using top
1 minute guide to using TOP
- Press x, this will make the sorted column in the table render in bold font
- Press > or < to change the sort column
- Press R, to toggle the sort from asc to desc and vice versa
- Press c, to expand the command column so that it includes the command plus all arguments
- Press ? to open help
- Press Esc to cancel and go back to the table
- Press W to save everything you've configured for next time
map b :buffer<Space>
set noautofocus
map gf createActiveTabbedHint
let blacklists = []
@cdosborn
cdosborn / verify_sns.py
Last active October 5, 2023 22:31 — forked from amertkara/aws_utils.py
Amazon SNS Notification Verification with Python, M2Crypto. When the SNS pushes a notification, a receiver should verify the origin/integrity of the push notification (AWS) using the signature and certificate provided in the notification data. The function `verify_sns_notification` below takes the request object and verifies the origin/integrity…
from flask import current_app
from cryptography import x509
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.asymmetric import padding
import base64
from urllib.parse import urlparse
import logging