Skip to content

Instantly share code, notes, and snippets.

View ryanbaldwin's full-sized avatar

Ryan Baldwin ryanbaldwin

  • Toronto, Canada
View GitHub Profile
@ryanbaldwin
ryanbaldwin / App.js
Created August 14, 2020 22:23
Reanimated 2 Interpolated Value Hell
import Animated, {
useDerivedValue,
useSharedValue,
useAnimatedStyle,
useAnimatedScrollHandler,
interpolate,
} from 'react-native-reanimated';
import {View, StyleSheet, FlatList, Text, Dimensions} from 'react-native';
import React, {useCallback} from 'react';

Keybase proof

I hereby claim:

  • I am ryanbaldwin on github.
  • I am hemingward (https://keybase.io/hemingward) on keybase.
  • I have a public key ASDMoypoaEWS-clLH9INBmwxuJHjdqhJxIQx1a8CIMT9ZAo

To claim this, I am signing this object:

@ryanbaldwin
ryanbaldwin / index_of.clj
Last active October 2, 2015 21:31
A solution to the classic "Find the index-of the first occurrence of substring in a string" problem, written in Clojure.
(ns ward.index-of)
(defn index-of
"Returns the first index where needle is found in haystack.
Returns -1 if the needle is not found in haystack."
[needle haystack]
(loop [n needle h haystack index 0]
(let [n-length (count n)
h-length (count h)]
(cond
(ns ward.applied-mergesort
(:refer-clojure :exclude [merge]))
(defn merge
"Merges two sorted lists into a single sorted list."
[right left]
(flatten (loop [r right, l left, results []]
(let [rhead (first r)
lhead (first l)]
(cond (nil? rhead) (conj results l)
@ryanbaldwin
ryanbaldwin / mergesort.clj
Last active October 2, 2015 22:34
A mergesort implemented in Clojure; Takes any number of unordered lists and merges them into a single merged list.
(ns ward.mergesort
(:refer-clojure :exclude [merge]))
(defn merge
"Merges two sorted lists into a single sorted list."
[right left]
(flatten (loop [r right, l left, results []]
(let [rhead (first r)
lhead (first l)]
(cond (nil? rhead) (conj results l)
@ryanbaldwin
ryanbaldwin / refactored_user_validator.clj
Last active August 29, 2015 14:10
Illustrates the impact on refactoring writing tests can have on a namespace.
(ns hipstr.validators.user-validator
(:require [noir.validation :as v]
[validateur.validation :refer :all]))
(def email-blank-msg
"Email is a required field")
(def email-format-msg
"The email's format is incorrect")
@ryanbaldwin
ryanbaldwin / user_validator_test.clj
Last active August 29, 2015 14:10
The full hipstr.test.validators.user-validator-test namespace
(ns hipstr.test.validators.user-validator-test
(:require [hipstr.validators.user-validator :as uv])
(:use clojure.test))
(defn validate-email [email]
"Validates the provided email for us, and returns the
set of validation messages for the email, if any."
(:email (uv/email-validator {:email email})))
(defn validate-username [username]
@ryanbaldwin
ryanbaldwin / user_validator_refactored.clj
Created November 29, 2014 21:57
The refactored user-validator namespace
(ns hipstr.validators.user-validator
(:require [noir.validation :as v]
[validateur.validation :refer :all]))
(def email-validator
(validation-set
(validate-with-predicate :email
#(v/is-email? (:email %))
:message-fn (fn [validation-map]
(if (v/has-value? (:email validation-map))
@ryanbaldwin
ryanbaldwin / user_validator.clj
Last active August 29, 2015 14:10
hipstr.validators.user-validator
(ns hipstr.validators.user-validator
(:require [noir.validation :as v]
[validateur.validation :refer :all]))
(defn validate-signup [signup]
"Validates teh incoming map of values from our signup form,
and returns a set of error messages for any invalid key.
Expects signup to have :username, :email, and :password."
(let [v (validation-set
(presence-of #{:email :password}
@ryanbaldwin
ryanbaldwin / tree
Created November 20, 2014 13:28
Outputs the directory tree in your terminal, all pretty like.
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'