Skip to content

Instantly share code, notes, and snippets.

View frankychung's full-sized avatar

Franky Chung frankychung

View GitHub Profile
@mlms13
mlms13 / CommonInfix.re
Last active December 5, 2019 10:07
Commonly-used infix functions in functional programming (Reason edition)
let (<|) = ('a => 'b, 'a) => 'b; // purescript and haskell use ($)
let (|>) = ('a, 'a => 'b) => 'b; // purescript uses (#)
let compose: ('b => 'c, 'a => 'b, 'a) => 'c;
let (<<) = compose; // purescript uses (<<<), haskell uses (.)
let composeFlipped: ('a => 'b, 'b => 'c, 'a) => 'c;
let (>>) = composeFlipped; // purescript uses (>>>)
@threepointone
threepointone / rethinkdb-caches.md
Last active October 22, 2022 15:49
better caches with rethinkdb

better caches with rethinkdb

TL;DR - smelly software engineer discusses using rethinkdb changefeeds for building caches, breaks hearts, shaves the cheerleader, shaves the world.

Let's talk about caches.

Imagine that you build UIs for an ecommerce company, possibly in a fancy office with free coffee and whatnot. You've just been asked to build a way for the marketing / sales folks to change landing pages whenever they're running campaigns. After a number of angry discussions involving the ux team about what they can and cannot change, you settle on a 'document' format for these pages. It could be json describing a tree of widgets of banners and carousels, or html, or yaml, or whatever. Maybe you also invent a dsl that marks out parts of the document as dynamic, based on request parameters or something. I dunno, I'm not your boss. You build a little ui over the weekend (with react? maybe!) that lets these folks login, drag and drop their banners, maybe upload an image or two, and save to database.

Yo

@jsdf
jsdf / immutableJSFormatter.js
Last active May 19, 2022 10:51
Chrome devtools formatter for Immutable-js
const immutableJSFormatter = {
header(x) {
if (x && x.toJS) return ['span', {}, x.toString()];
return null;
},
hasBody(x) {
return x && x.toJS;
},
body(x) {
return ['span', {}, JSON.stringify(x.toJS(), null, 2)];

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

var EventEmitter = require('events').EventEmitter;
var mergeInto = require('react/lib/mergeInto');
module.exports = createStore;
function createStore(initialState) {
var events = new EventEmitter();
var state = initialState || {};
return {
@ryanflorence
ryanflorence / Dialog.js
Last active January 9, 2021 16:12
React Portal.js
var Dialog = React.createClass({
mixins: [Portal],
createPortal: function() {
this.dialog = $(this.portalNode).dialog({
autoOpen: false,
title: this.props.title,
close: this.props.onClose
}).data('ui-dialog');
},
@andrey-kazakov
andrey-kazakov / content_repeat.js.coffee
Created January 23, 2013 23:26
This AngularJS directive, when added to element, repeats it's content as many times as length of given array (almost like ng-repeat). The main difference is that DOM, once built, don't being changed on each $digest(). If you want to force the changing of repeated content, you should emit an event 'invalidateView' with (optionally) name of the sc…
angular
.module('ContentRepeat', [])
.directive 'contentrepeat', ($compile) ->
priority: 1000
terminal: true
compile: (element, attr, linker) ->
template = $compile(element.html())
element.empty()
(scope, self, attr) ->
@taylor
taylor / HOWTO-bitlbee+hipchat.mkd
Created December 16, 2012 01:13
Using bitlbee with HipChat

Using bitlbee with HipChat

Initial setup

  • account add jabber USERNAME@chat.hipchat.com 'PASSWORD'
  • account hipchat set nick_source full_name
  • account hipchat set resource bot
  • account hipchat on