Skip to content

Instantly share code, notes, and snippets.

@StevePotter
StevePotter / main.rb
Last active March 18, 2019 14:23
Quicksort Ruby created by StevePotter - https://repl.it/@StevePotter/Quicksort-Ruby
##
# A quick sort implementation I made for fun in Ruby.
def quick_sort(values)
return values if values.size < 2
pivot_index = values.size - 1
pivot_value = values[pivot_index]
curr_index = 0
(values.size - 1).times do
curr_value = values[curr_index]
# less than or equal, leave the item where it is
@StevePotter
StevePotter / Subsets (js)
Last active March 15, 2019 15:36
Problem is: calculate all subsets of a given set. Like [1,2,3] will give [[1,2], [1,3], [2,3], [1,2,3]]
/*
Takes an array of indices within a set and increments them one
position, returning null if it cannot be incremented.
Example: if a set has 4 elements:
[0,1] -> [0,2]
[0,3] -> [1,2]
[1,2] -> [1,3]
[2,3] -> null
*/
const incrementPosition = (indices, indexToIncrement, maxIndex) => {
@StevePotter
StevePotter / readme.md
Last active December 15, 2018 18:21
App State Container Improvements

Improvements over Redux

  • Less boilerplate (no actions, for example)

Features

  • Declare a state container using a HOC
  • Easily add 'reducers', which become methods to the state object
  • Built-in update and reset functions
  • Add auto-calculated fields (like 'canNavigateToCompositionSection')
  • Easy persistence (sessionState)
  • Per-route persistance
@StevePotter
StevePotter / cloudSettings
Last active February 9, 2019 15:04
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-02-09T15:04:07.362Z","extensionVersion":"v3.2.4"}
Add this to ~/.bash_aliases
-------------------
##### git #####
alias g-delete-all-branches-except-master="git branch | grep -v "master" | xargs git branch -D"
alias gs="git status"
alias ga="git add -A"
alias gc="git commit -m"
alias gac="ga && gc"
alias gpu="git push origin HEAD"
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
// @flow
/*
A simple spacer component to give room for the status bar.
Thanks to https://github.com/jgkim/react-native-status-bar-size/blob/master/StatusBarSizeIOS.js
*/
/* eslint-disable react-native/split-platform-components */
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { View, StatusBar, StatusBarIOS, NativeModules, Platform, StyleSheet } from 'react-native'
/* @flow */
import React from 'react'
import { Header } from 'react-navigation'
import { View, StyleSheet } from 'react-native'
import NavBackButton from './NavBackButton'
import StatusBarSpacer from '../components/StatusBarSpacer'
const styles = StyleSheet.create({
root: {
@StevePotter
StevePotter / ConditionalView.cs
Last active December 16, 2019 16:56
A WPF control that creates its content based on the value of some property in DataContext. This is great when you have a property like "Status" and want to display a particular control for each status.
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wpf
{
/// <summary>
@StevePotter
StevePotter / gist:603b366873bb99fd8afd
Created September 3, 2014 13:30
A mixin for bootstrap react that adds validation and value conversion to forms.
//use this mixin to get validation support and some helpful input functions
FormMixin = {
autoHandleChange: function(field, e)
{
var value = (this.refs[field] && this.refs[field].getValue) ? this.refs[field].getValue() : e.target.value;
stateUpdate = {}
stateUpdate[field] = value
this.setState(stateUpdate, function() {
stateUpdate = {}
stateUpdate[field + "Error"] = this.validateSingle(field)