Skip to content

Instantly share code, notes, and snippets.

View ahmed1490's full-sized avatar

Ahmed Abbas ahmed1490

View GitHub Profile
export (reducerMap, initialState) => (state = initialState, action) => {
const reducer = reducerMap[action.type];
return reducer ? reducer(state, action) : state;
}
@vancluever
vancluever / multiarraysort.go
Created December 10, 2015 21:48
Go: Sort an array of interfaces so that strings are on top
// This is a very basic demonstration of how to implement sort.Interface
// to do some custom sorting. Here, a slice of interfaces
// (ints and strings) are sorted so that the strings are on top.
// There is no other sorting of the elements, but the example
// provides a layout that can be used to implement more complex sorting.
package main
import "fmt"
import "sort"
@marty-wang
marty-wang / gist:5a71e9d0a6a2c6d6263c
Last active June 27, 2024 13:34
Compile and deploy React Native Android app of Release version to device.
Disclaimer: The instructions are the collective efforts from a few places online.
Nothing here is my original. But I want to put them together in one place to save people from spending the same time as I did.
First off, bundle.
==================
1. cd to the project directory
2. Start the react-native packager if not started
3. Download the bundle to the asset folder:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
@paulirish
paulirish / what-forces-layout.md
Last active April 19, 2025 04:59
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@cdaringe
cdaringe / test-coins-webpack-dev-server.js
Created July 23, 2015 22:14
test-coins-webpack-dev-server
'use strict';
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config.js');
var fs = require('fs');
var port = process.env.WEBPACK_DEV_SERVER_PORT || 22222;
var host = '0.0.0.0';
var srv = new WebpackDevServer(webpack(config), {
contentBase: '../',
@chantastic
chantastic / on-jsx.markdown
Last active November 10, 2024 13:39
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@santtu
santtu / lambda-downscale-example.js
Created April 24, 2015 21:13
Example of an AWS Lambda function implementing a custom termination policy for auto scale group
console.log('Loading function');
var minInstances = 1;
var region = 'us-east-1';
var EventEmitter = require("events").EventEmitter;
var aws = require('aws-sdk');
var http = require('http');
@jamesarosen
jamesarosen / upgrading.md
Last active September 29, 2015 13:45
Upgrading to Ember-CLI 0.2.0

I upgraded a small app from ember-cli from 0.1.11 to 0.2.0 today. It took a couple hours. Here are some notes.

Prep

First, I read the release notes.

ember init

I recommend committing your changes right before running ember init. That way, you can accept all the overwrites and easily discard the ones you don't want. kellyselden maintains a repo called ember-cli-output that tracks the changes in what ember init generates over time. You can find the v0.2.0 changes here.

@sebmarkbage
sebmarkbage / Enhance.js
Last active February 10, 2025 06:23
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@supinf
supinf / s3-invalidation.js
Last active January 7, 2023 08:57
AWS Lambda script:: CloudFront Invalidations which are triggered by s3 events.
console.log('Loading event');
var Q = require('q');
var aws = require('aws-sdk');
var cloudfront = new aws.CloudFront();
exports.handler = function (event, context) {
//_log('Received event: ', event);
var bucket = event.Records[0].s3.bucket.name;