Skip to content

Instantly share code, notes, and snippets.

View alexkirsz's full-sized avatar

Alex Kirszenberg alexkirsz

View GitHub Profile
@alexkirsz
alexkirsz / EventMixin.coffee
Created April 21, 2014 00:52
A mixin that transforms react components into event emitters and receivers
isEventComponent = (component) ->
component._listeners?
findNearestEventComponent = (component) ->
if (isEventComponent component)
component
else if component._owner
findNearestEventComponent component._owner
else
null
@alexkirsz
alexkirsz / example.coffee
Created April 21, 2014 01:45
Example use of EventMixin
Button = react.createClass
displayName: 'Button'
mixins: [EventMixin]
handleClick: ->
@emit 'click'
@bubble 'dropdown.open', x: 10, y: 20 # Bubble the event up the component chain
render: ->
# I can do
React.DOM.div null,
React.DOM.div null, 'hello'
React.DOM.div null, 'world'
# Instead of
React.DOM.div null, [
React.DOM.div null, 'hello'
React.DOM.div null, 'world'
]
let reqImage = require.context('./images', true, /\.png/);
reqImage.keys().forEach(reqImage);
function TorrentStore() {
EventEmitter.call(this);
}
TorrentStore.prototype = Object.assign({}, EventEmitter.prototype, { ... });
@alexkirsz
alexkirsz / ForceCaseSensitivityPlugin.js
Last active February 23, 2017 13:38
Force case sensitivity in webpack
/*
The MIT License (MIT)
Copyright (c) 2015 Alexandre Kirszenberg
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTI
@alexkirsz
alexkirsz / gist:78fe94eb84451a55ba9e
Last active August 29, 2015 14:20
Date to/from date and time inputs
let [date, time] = dateObj.toISOString().split('T');
time = time.split('.')[0].split(':').slice(0, 2).join(':');
let dateObj = new Date(`${date}T${time}.000Z`);
@alexkirsz
alexkirsz / gist:ec9f5d4479efc115e533
Last active August 29, 2015 14:20
Children propType validation
let propTypes = {
children(props, propName) {
let errors = [];
React.Children.map(props[propName], child => {
if (child.type !== Foo) {
errors.push(`${child.key} is not a Foo element`);
}
});
if (errors.length > 0) {
return new Error(errors.join(', '));
@alexkirsz
alexkirsz / OCaml-REPL-windows.sublime-build
Created October 4, 2015 11:27
ST3 Build Systems for OCaml
{
"shell_cmd": "type $file | ocaml",
"selector": "source.ml"
}
@alexkirsz
alexkirsz / script.js
Last active August 9, 2020 10:31
YouTube Player for edX
// ==UserScript==
// @name YouTube Player for edX
// @namespace morhaus
// @version 1.1
// @description Replace the default edX video player with the YouTube player
// @author Alexandre Kirszenberg <alexandre.kirszenberg@gmailcomr>
// @match https://courses.edx.org/*
// @match https://courses.ionisx.com/*
// @grant none
// ==/UserScript==