Skip to content

Instantly share code, notes, and snippets.

View wuct's full-sized avatar

CT Wu wuct

View GitHub Profile
@wuct
wuct / config-overrides.js
Last active October 5, 2022 17:17
This is a react-app-rewired config which allows you to import PureScript code in a create-react-app project directly.
module.exports = function override(config, env) {
config.module.rules = config.module.rules.map(rule => {
if (rule.oneOf instanceof Array) {
return {
...rule,
// create-react-app let every file which doesn't match to any filename test falls back to file-loader,
// so we need to add purs-loader before that fallback.
// see: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/config/webpack.config.dev.js#L220-L236
oneOf: [
{
@wuct
wuct / Complex.purs
Last active September 2, 2017 17:30
PureScript by Example CH6 Exercises
module Complex where
import Prelude
import Data.Eq
newtype Complex = Complex
{ real :: Number
, imaginary :: Number
}
@wuct
wuct / ec2MongoUpgrade.md
Created June 13, 2017 15:42 — forked from mattjay/ec2MongoUpgrade
Increase the disk space on a MongoDB EC2 Instance in Amazon Web Services
  1. Create a Snapshot of the current EC2 instance running Mongo. First, note down the Volume ID from your Instance list since for whatever reason you can't see any instance info in the Snapshot page. Second, go to the Snapshot page and click [Create Snapshot]. Choose the Volume ID you just noted down and name the Snapshot and create it.

  2. Create a new Volume with the backup Snapshot. In your instance list note the Availability Zone of the instance you are trying to upgrade. Go to the Volumes page and click [Create Volume]. Pick Standard and enter how many GB you'd like to create. This should be larger than the Volume you just created the Snapshot from. Then from the drop down choose the Snapshot you just created and click create. Also choose the Availability Zone that the instance you are upgrading is in as they must be the same.

  3. Find the instance you'd like to upgarde in the Instances list and note the name of the disk which will be next to "Block devices" (most likely /dev/sda1).

  4. Stop the Instance

@wuct
wuct / promise-fmap.js
Last active November 3, 2018 20:18
Let JavaScript Promise be a functor
Promise.prototype.fmap = Promise.prototype.then
Promise.resolve('yolo')
.fmap(str => str + ' swag!')
.then(console.log) // "yolo swag!"
@wuct
wuct / HoCs.js
Created April 8, 2016 10:18
Three types of HoCs
const hoc = BaseComponent =>
BaseComponent
const hoc = BaseComponent =>
() => <BaseComponent />
const hoc = BaseComponent =>
class extend React.Component {
render = () => <BaseComponent />
}
@wuct
wuct / orderFood.js
Created March 10, 2016 06:49 — forked from lulalachen/orderFood.js
Redux Action Inprovemnet
import { genAuthHeaderFromState, genTokenFromState } from '../api';
import { default as apiStack } from '../api/apiStack';
import { createFetch, auth, body, method } from 'http-client';
// redux-api-middleware
export const orderList = () => ({
[CALL_API]: ({
endpoint: 'http://food.com/order/list/',
method: 'GET',
headers: genAuthHeadersFromState,
@wuct
wuct / Component.js
Last active April 23, 2016 09:29
Recopose Compnents Syntax
// 1
// cons:the component name appears twice
const Component = compose(
// HOC
)(({
// ...destructured props
}) =>
// react element
);
@wuct
wuct / functionnal-switch.js
Last active March 7, 2016 16:05
A functional implementation of switch
// simple example
const isFruitOrVegetable = switch(
case('apple', 'isFruit'),
case('orange', 'isFruit'),
case('eggplant', 'isVegetable'),
default('isFruit')
);
isFruitOrVegetable('apple') // isFruit
@wuct
wuct / AnotherAntiPattern.js
Last active February 19, 2016 03:05
Nesting children is also an anti-pure-render pattern.
// Consider <Button /> is a pure render component
import { pure } from 'recompose';
const Button = pure(props =><button>{props.children}</button>);
const App = () => <div>
Call me maybe?
<Button><IconPhone /> Call</Button>
</div>
@wuct
wuct / bind.js
Last active January 28, 2016 02:49
How to bind methods in React components
// 在 constructor 內 bind
export default class extends React.Component {
constructor(...args) {
super(...args)
this.doSomething = this.doSomething.bind(this)
}
doSomething() {}