Skip to content

Instantly share code, notes, and snippets.

View audiolion's full-sized avatar
⌨️
coding

Ryan Castner audiolion

⌨️
coding
View GitHub Profile
<div css={{
color: 'red',
...(isActive ? color: 'blue' : {}),
}} />
<div css={[
{ color: 'red' },
isActive ? { color: 'blue' } : undefined,
]} />
import qs from 'query-string';
import { useHistory, useLocation } from 'react-router';
function useSynchronizeQueryParams({ topic }) {
const { search, pathname } = useLocation();
const history = useHistory();
const params = qs.parse(search);
React.useEffect(() => {
@audiolion
audiolion / device-setup.js
Last active January 21, 2019 23:44
show code that is producing twilio client error
state = {
device: new Twilio.Device();
};
state.device = state.device.setup(token, { allowIncomingWhileBusy: true });
resumeTwilioDevice = async () => {
if (state.device.audio &&
state.device.audio._audioContext &&
state.device.audio._audioContext.state === 'suspended'
// App.tsx
export const App = () => (
<BrowserRouter>
<Route path="/users" component={UsersConnector} />
</BrowserRouter>
);
// UsersConnector.tsx
export const UsersConnector: React.SFC<RouteComponentProps> = (props) => (
<Query query={UsersList}>
/**
*
* A very simple refactoring that eliminates the need for a comment "This is the first attempt".
*
* I am not going to go into the details of why code is better than comments, books like
* The Pragmatic Programmer and Fowler's Refactoring provide well-reasoned arguments as to why
* this is the case.
*
*/
import React from "react";
let hasWindow = typeof window !== "undefined";
class WindowSize extends React.Component {
state = {
width: hasWindow && window.innerWidth,
height: hasWindow && window.innerHeight,
};
@audiolion
audiolion / sentry_error_handler.py
Created May 4, 2018 13:41 — forked from danigosa/sentry_error_handler.py
Sentry Logger Event Hook for Python API Star 0.5+ (tested on 0.5.10)
import sys
from os import environ
import logging
from apistar import http
from raven import Client
from apistar import App
from apistar.test import TestClient
from apistar import Route
settings = {
@audiolion
audiolion / example.py
Last active March 24, 2023 01:34
pytest assert vs self.assertEqual
class TestSomething(TestCase):
def test_something(self):
assert something['message'] == 'Asserting that a very long message statement is as expected in this test case here, the issue is that its all on one line with no easy way to conform to PEP-8 besides adding "\" to continue the one line statement in python.'
self.assertEqual(
something['message'],
('Asserting that a very long message statement is as expected'
' in this test case here, the issue is that its all on one line'
' with no easy way to conform to PEP-8 besides adding "\" to'
' continue the one line statement in python.'
' With assertEqual and the function structure we can easily'
@audiolion
audiolion / TodosList.jsx
Created June 30, 2017 00:43
trouble a brewin' in some reactive waters, redux!
import React from 'react';
import { connect } from 'react-redux';
export class TodosList extends Component {
static propTypes = {
todos: PropTypes.arrayOf(todoPropTypes).isRequired,
isLoading: PropTypes.bool.isRequired,
hasErrored: PropTypes.bool,
dispatch: PropTypes.func.isRequired,
};
@audiolion
audiolion / api.py
Last active October 17, 2016 19:45
# refactored code
# -*- coding: utf-8 -*-
"""API Endpoints for the Calendar
Endpoints designed to be called with AJAX requests and retrieve the events
that should populate the webpage's calendar.
"""
from django.utils.html import strip_tags
from django.http import HttpResponse