Skip to content

Instantly share code, notes, and snippets.

View ianwcarlson's full-sized avatar

Ian Carlson ianwcarlson

  • Albuquerque, NM
View GitHub Profile
@ianwcarlson
ianwcarlson / convertSerializedHtmlToReactElements.js
Last active November 18, 2020 19:14
Convert serialized html to react elements
// This is actually a nodejs script using string templates to demonstrate feasibility
// The potential use case for something like this is dynamically generating react
// element at run time while only supported a small subset of valid HTML elements.
// A full-blown HTML parser is also much larger and complex.
const supportedTags = [
{
tag: 'sup',
regex: /<sup>[^<>].*?<\/sup>/,
createReactElement: content => `<sup>${content}</sup>`,
@ianwcarlson
ianwcarlson / git-branch-detail.sh
Created February 25, 2019 16:37
Git Branch Detail
for k in `git branch | sed s/^..//`; do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k --`\\t"$k";done | sort
// This file doesn't go through babel or webpack transformation.
// Make sure the syntax and sources this file requires are compatible with the current node version you are running
// See https://github.com/zeit/next.js/issues/1245 for discussions on Universal Webpack or universal Babel
const { createServer } = require('http')
const express = require('express')
const { parse } = require('url')
const next = require('next')
const path = require('path');
const dev = process.env.NODE_ENV !== 'production'
@ianwcarlson
ianwcarlson / substring.py
Last active July 29, 2018 19:10
Find a string within a string without using a library method
# Find a string within a string and return the found index
# Found index will be -1 if string not found
def substring(strToSearch, strToFind):
totalLength = len(strToSearch)
findLength = len(strToFind)
for idx in range(0, totalLength):
if (strToSearch[idx:idx + findLength] == strToFind):
return idx
@ianwcarlson
ianwcarlson / fibonacci_locator_with_recursion.py
Last active July 29, 2018 16:59
Implement a function recursively to get the desired Fibonacci sequence value
"""Implement a function recursively to get the desired
Fibonacci sequence value.
Your code should have the same input/output as the
iterative code in the instructions."""
prev1 = 0
prev2 = 1
count = 0
def recursive(prev1, prev2, count, terminal):
@ianwcarlson
ianwcarlson / quick_sort.py
Created July 29, 2018 16:56
Quick sort implementation in Python
"""Implement quick sort in Python.
Input a list.
Output a sorted list."""
def sort_slice(list_slice):
# pivot location always starts on the right
end_idx = len(list_slice) - 1
pivot_idx = end_idx
# compare location always starts on the left
compare_idx = 0
while(True):
@ianwcarlson
ianwcarlson / Example.jsx
Last active June 25, 2017 23:00
OpacityAnimation Example Usage
import OpacityAnimation from './OpacityAnimation.jsx';
const Example = ({ showBox }) => (
<OpacityAnimation>
{showBox
? <div
key="Example"
style={{
backgroundColor: 'red',
height: '30px',
@ianwcarlson
ianwcarlson / OpacityAnimation.css
Last active June 25, 2017 23:26
Goto React Opacity Animation CSS
/* placeholder for named import */
.opacityTransition {};
.opacityTransition-appear {
opacity: 0;
}
.opacityTransition-appear.opacityTransition-appear-active {
opacity: 1;
/* autoprefix transition as needed */
@ianwcarlson
ianwcarlson / OpacityAnimation.jsx
Last active June 25, 2017 23:20
Goto React Opacity Animation
import React from 'react';
import css from './OpacityAnimation.css';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
const OpacityAnimation = ({ children }) => (
<ReactCSSTransitionGroup
transitionName={css.opacityTransition}
transitionAppear
transitionEnter
transitionLeave
@ianwcarlson
ianwcarlson / immutable_v4.x.x.js
Last active March 12, 2018 15:38
Stop-gap Immutable Flow Definitions with Working Records
/**
* This file provides type definitions for use with the Flow type checker.
*
* An important caveat when using these definitions is that the types for
* `Collection.Keyed`, `Collection.Indexed`, `Seq.Keyed`, and so on are stubs.
* When referring to those types, you can get the proper definitions by
* importing the types `KeyedCollection`, `IndexedCollection`, `KeyedSeq`, etc.
* For example,
*
* import { Seq } from 'immutable'