Skip to content

Instantly share code, notes, and snippets.

merge

[s1] ----a-----b--c---->
[s2] o----------------->
   s3 = s1.merge(s2)
[s3] o---a-----b--c---->

startsWith, merge

// Drag n Drop, using streaming paradigm
const fromEvent = Rx.Observable.fromEvent
const widget = document.getElementById('widget')
const container = document.getElementById('container')
// streams
const mouseDowns = fromEvent(widget, 'mousedown')
const mouseUps = fromEvent(container, 'mouseup')
const mouseMoves = fromEvent(container, 'mousemove')
abstract class AngularShim extends React.Component<Props, State> {
private _div
public state = {
scope: null
}
componentWillMount() {
const scope = Object.assign($rootScope.$new(true), { props: this.props }, this.getScopeMethods())
this.setState({scope})
}
// quicksort sorting algorithm, in 2 lines of code
let quicksort = ([a, ...as]) => {
if (a == null) return as
return quicksort(as.filter(x => x <= a))
.concat([a])
.concat(quicksort(as.filter(x => x > a)))
}
let test1 = [5,1,2,3,5,6];
@albertywu
albertywu / hubot.coffee
Created November 3, 2015 03:45
log any chat to redshift?
module.exports = (robot) ->
robot.hear /^(.+)$/i, (res) ->
logToRedshift
message: res.match[1]
user: res.message.user.name.toLowerCase()
@albertywu
albertywu / speedTest.coffee
Last active October 13, 2015 18:56
Boolean reduction via _.every, _.reduce, _.forEach, vanilla js
trues = (n) -> [1..n].map Boolean
# array of functions to be speed tested
tests = [
[
(
(bools) -> _.every bools # .097ms
)
trues(1000)
@albertywu
albertywu / tagShape.md
Last active August 29, 2015 14:26
tag field shape
field =
  dataType: 'reference'
  options: [... tagValueIds ...]
  format_json:
    contexts: [
      {
        name: 'iPadNoteCreationModal'
        tagValueIds: [...]
 },
@albertywu
albertywu / getUniqueClasses
Created May 23, 2015 04:50
Short snippet that returns an array of unique classes in the DOM
/* returns an array of unique classes in the DOM */
var getUniqueClasses = function() {
var elementArray = [].slice.call(document.querySelectorAll('*'));
return _(elementArray)
.pluck('classList')
.map(_.toArray)
.flatten()
.unique()
@albertywu
albertywu / screeningDetails.coffee
Last active August 29, 2015 14:16
screening details directives
<!-- Does this make sense for our component APIs? -->
<smartlist-details
smartlist-id="smartlistId"
></smartlist-details>
<ipad-subscriptions
smartlist-id="smartlistId"
user-id="userId"
fund-id="fundId"
@albertywu
albertywu / screeningDetails.html
Created March 6, 2015 22:56
screeningDetails
<h1>Screen Details</h1>
<ul ng-if="smartlist">
<li>
<span>Created By</span>
<span>{{ smartlist.createdBy | userShortName }}, {{ smartlist.createdOn | date: "shortDate" }}</span>
</li>
<li>