Skip to content

Instantly share code, notes, and snippets.

@dnlserrano
dnlserrano / create.json.jbuilder
Last active October 18, 2017 01:40
Custom Token Authentication SessionController with DRY Authenticatable Logout
json.success true
json.data do
json.auth_token @user.authentication_token
json.message "login successful"
end
//! Monad chain macro in Rust
//!
//! A typical usage is to avoid nested match expressions.
//!
//! Supports:
//! - Pattern matching
//! - Or expressions (A | B => ...)
//! - Guarded statements (x if <cond> => ...)
#[feature(macro_rules)];
@erikbrannstrom
erikbrannstrom / ConfirmButton.jsx
Created March 21, 2014 15:16
ConfirmButton component for React. Require two clicks with a minimum delay between in order to go through with the action.
var React = require('react');
var ConfirmButton = React.createClass({
propTypes: {
onClick: React.PropTypes.func,
waitTime: React.PropTypes.number,
confirmText: React.PropTypes.string,
},
getInitialState: function() {
@zshamrock
zshamrock / range-drop-filter-jvm
Last active August 29, 2015 13:57
range->drop->filter in Scala, Clojure and Java 8
(0 until 12).drop(4).filter(_ % 2 == 0)
(->> (range 12) (drop 4) (filter #(= (mod % 2) 0)))
LongStream.range(0, 12).skip(4).filter((n) -> (n % 2) == 0)
// of course for the Java the whole story is:
import java.util.Arrays;
import java.util.stream.LongStream;
@stuarthalloway
stuarthalloway / schema_history.clj
Last active March 31, 2017 21:40
Complete schema history of a live Datomic database
;; Complete schema history for a live Datomic database.
(require
'[clojure.pprint :as pp]
'[clojure.set :as set]
'[datomic.api :as d])
;; fill this in with your own database connection
(def uri "datomic:dev://localhost:4334/my-db")
(def conn (d/connect uri))
(def db (d/db conn))
@jmreidy
jmreidy / todoApp.jsx
Last active January 4, 2016 01:59
modularizing jsx. Makes use of [grunt-browserify](https://github.com/jmreidy/grunt-browserify) with [reactify](https://github.com/andreypopp/reactify) for compiling JSX as a transform.
var TodoItem = require('../templates/todoItem.jsx');
//in render fn...
var todoItems = mori.into_array(mori.map(function (todo) {
idx++;
return TodoItem.call(this, todo, idx);
}.bind(this), shownTodos));
@zbyte64
zbyte64 / alpaca-om.cljs
Created January 16, 2014 01:42
Render alpacajs form in OM (clojsurescript react.js library); AKA render raw html in OM
(defn show-form [data _]
(om/component
(let [schema (:current-form data)
alpaca-html (.html (.alpaca (js/jQuery. "<div/>") (clj->js {:schema schema})))
form-html (js/React.DOM.div (clj->js {:dangerouslySetInnerHTML {:__html alpaca-html}}))]
form-html)))
/**
* react-catalyst.js
*
* LinkedState for Facebook's React UI Library. Add support for
* deep path state access.
*
* Author: Tung Dao <[email protected]>
*
* Usage:
*
@pk11
pk11 / reactjs.js
Last active August 29, 2016 17:42
/** @jsx React.DOM */
/**
* Our component structure will look like the following:
* - WikiBox
* -- AutoCompleteBox
* --- AutoComplete
*/
// this component renders a single entity coming from wikipedia