Skip to content

Instantly share code, notes, and snippets.

View StevenConradEllis's full-sized avatar

Steven Ellis StevenConradEllis

View GitHub Profile
package main
import (
"fmt"
"golang.org/x/exp/constraints"
)
type Number interface {
constraints.Float | constraints.Integer | constraints.Complex
@StevenConradEllis
StevenConradEllis / Social.java
Last active October 2, 2019 20:24
Social Network Dynamic Connectivity
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Social {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new File("/Users/steven/demo/friends.txt"));
int n = 100; // 100 individuals
@StevenConradEllis
StevenConradEllis / WeightedQuickUnion.java
Created October 2, 2019 07:10
Weighted Quick Union
public class WeightedQuickUnion {
private int[] id; // id[i] = parent of i
private int[] sz; // sz[i] = number of objects in subtree rooted at i
private int count; // number of components
// Create an empty union find data structure with N isolated sets.
public WeightedQuickUnion(int N) {
count = N;
id = new int[N];
sz = new int[N];
public class QuickUnion {
private int[] id; // id[i] = parent of i
private int count; // number of components
// instantiate N isolated components 0 through N-1
public QuickUnion(int N) {
id = new int[N];
count = N;
for (int i = 0; i < N; i++) {
id[i] = i;
public class QuickFind {
private int[] id;
private int count;
public QuickFind(int N) {
count = N;
id = new int[N];
for (int i = 0; i < N; i++)
id[i] = i;
}
@StevenConradEllis
StevenConradEllis / Map.tsx
Created April 10, 2019 15:10
Using capacitor
import React from 'react';
import {connect} from 'react-redux';
import {actions, RootState, selectors} from '../store';
import Map from '../components/Map';
import {IonHeader, IonToolbar, IonButtons, IonMenuButton, IonTitle, IonContent} from '@ionic/react';
import {Location} from '../store/locations/types';
import {Plugins} from '@capacitor/core';
type Props = typeof mapDispatchToProps & ReturnType<typeof mapStateToProps>;
const {Geolocation} = Plugins;
@StevenConradEllis
StevenConradEllis / BranchesReducer.ts
Created April 10, 2019 13:22
Example of Redux Reducer
import * as branches from './actions';
import { ActionType, getType } from 'typesafe-actions';
import { BranchState } from "./types";
const defaultState: BranchState = {
branches: []
}
export type BranchAction = ActionType<typeof branches>;
@StevenConradEllis
StevenConradEllis / AppStack.tsx
Created April 10, 2019 13:16
IonTabs, Route
import React from 'react';
import MapView from './Map';
import About from './About';
import { IonTabs, IonTabButton, IonIcon, IonLabel, IonRouterOutlet, IonTabBar, IonPage } from '@ionic/react';
import { Route, Redirect } from 'react-router';
import FishesPage from "./FishesPage";
import BranchList from "./BranchList";
import BranchDetail from "./BranchDetail";
import FishDetail from "./FishDetail";
@StevenConradEllis
StevenConradEllis / App.tsx
Created April 10, 2019 13:09
IonApp, Provider, Route
import React from 'react';
import '@ionic/core/css/core.css';
import '@ionic/core/css/ionic.bundle.css';
import {IonApp} from '@ionic/react';
import store from "./store/store";
import {BrowserRouter as Router, Route} from 'react-router-dom';
import {Provider} from 'react-redux';
import AppStack from "./pages/AppStack";
const App = () => (