Skip to content

Instantly share code, notes, and snippets.

View audiolion's full-sized avatar
⌨️
coding

Ryan Castner audiolion

⌨️
coding
View GitHub Profile
###
# Attribute Branching Impurity Calculator
# Zachary Friss
# CSCI 420
# Written for Python 3.4
###
from statistics import *
from math import *
@audiolion
audiolion / loop.py
Created October 17, 2016 13:42
loop through items and perform an action at a specified count
divisor = 100
company_names = ['ALP','FORRESTER','GE Aero', ... ]
for index, company_name in enumerate(company_names):
if index % divisor == 0 and index != 0:
# perform action on each 100 count
# perform normal actions outside of tallying 100 if applicable
@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
@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 / 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 / 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 = {
import React from "react";
let hasWindow = typeof window !== "undefined";
class WindowSize extends React.Component {
state = {
width: hasWindow && window.innerWidth,
height: hasWindow && window.innerHeight,
};
/**
*
* 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.
*
*/
// App.tsx
export const App = () => (
<BrowserRouter>
<Route path="/users" component={UsersConnector} />
</BrowserRouter>
);
// UsersConnector.tsx
export const UsersConnector: React.SFC<RouteComponentProps> = (props) => (
<Query query={UsersList}>
@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'