Skip to content

Instantly share code, notes, and snippets.

Avatar
😃

Jason Neylon jasonneylon

😃
View GitHub Profile
@jasonneylon
jasonneylon / recent.sh
Created Aug 23, 2017
Everything I have done since a specfic date in all the git subfolders
View recent.sh
for i in *; do ( cd $i; pwd; git --no-pager log --since="2016-02-12T16:36:00-07:00" --author jason --format=oneline; pwd ); done | less
View timeout.cljs
(defn timeout [ms]
(let [c (chan)]
(js/setTimeout (fn [] (close! c)) ms)
c))
(defn run-kmean
[]
(go
(dotimes [iteration 10]
(<! (timeout 1000))
View subscription-every-second.elm
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every second NextRunTicktions : Model -> Sub Msg
View random.elm
randomPoints : Generator (List(Point))
randomPoints =
Random.list 200 (Random.map (\(x, y) -> Point x y) (Random.pair (int 1 999) (int 1 399)))
-- here we create a command that the elm runtime will execute and then pass the results back via the Update function
initialModel : (Model, Cmd Msg)
initialModel =
(Model [] [] 6 0 False, (Random.generate DrawPoints randomPoints))
View random.cljs
(defn random-point []
{:x (rand-int 1000) :y (rand-int 500)})
@jasonneylon
jasonneylon / passphrases.clj
Created Nov 30, 2016
Generate passphrases (and DNA!) using clojure.spec
View passphrases.clj
(require '[clojure.spec :as s])
(require '[clojure.spec.gen :as gen])
;; PASSPHRASES - generate a random 5 word passphrase
;; naive approach was to generate a random string and contrain to match a five word pattern
;; however this hit 100 generation limit imposed by clojure.spec
(defn words [str] (clojure.string/split str #" "))
(def five-words? (comp (partial = 5) count words))
(gen/generate (s/gen (s/and string? five-words?)))
View react-jquery-pub-sub.js
// publish an event when a user selects and address in our React component
onAddressSelected(addressIndex) {
this.state.selectedAddressIndex = addressIndex;
this.state.address = Object.assign({}, this.state.addresses[index]);
this.setState(this.state);
// using tinypubsub to wrap our js events
$.publish('address.selected', {address: this.state.address, type: this.props.addressType});
}
....
@jasonneylon
jasonneylon / submit-form-validating-react-component.js
Created Oct 22, 2015
Example of submitting form and validating javascript
View submit-form-validating-react-component.js
// When submitting the form we use standard jquery validation
$form.submit(function handleSubmit(ev) {
// call the React address component instance and ask it to validate itself and return any errors
const errors = addressInstance.validate();
// if there are errors cancel the form submit
if(errors.length > 0) {
ev.preventDefault();
}
....
}
@jasonneylon
jasonneylon / creating-address-component.js
Last active Oct 22, 2015
Creating React address component
View creating-address-component.js
// The props for the React component are initally set from the server side
const addressConfig = #{@address_config.to_json};
// the component is rendered inside the form at a marker div embedded in the server generated HTML
const addressInstance = React.render(
React.createElement(Address, addressConfig),
document.getElementById("#billing_address")
);
You can’t perform that action at this time.