Skip to content

Instantly share code, notes, and snippets.

View oyeanuj's full-sized avatar

Anuj oyeanuj

View GitHub Profile
@designspin
designspin / server-middleware-reactapplication-index.js
Created July 13, 2017 21:38
Styled-Components with React Universally
import React from 'react';
import Helmet from 'react-helmet';
import { renderToString, renderToStaticMarkup } from 'react-dom/server';
import { StaticRouter } from 'react-router-dom';
import { AsyncComponentProvider, createAsyncContext } from 'react-async-component';
import asyncBootstrapper from 'react-async-bootstrapper';
import config from '../../../config';
import ServerHTML from './ServerHTML';
class MyEditor {
onPaste = (_event, paste, state) => {
if (paste.type === "text" && isUrl(paste.text) && state.isCollapsed) {
return (
state
.transform()
.insertText(paste.text)
.extend(0 - paste.text.length)
.wrapInline({
type: "link",
import { Plugin } from 'uppy';
export default class ReduxEmitter extends Plugin {
constructor(core, opts) {
super(core, opts);
this.type = 'redux';
this.id = 'ReduxEmitter';
this.title = 'Redux Emitter';
// set default options
const defaultOptions = {};
@bvaughn
bvaughn / react-lifecycle-cheatsheet.md
Last active March 2, 2023 13:29
React lifecycle cheatsheet

React lifecycle cheatsheet

Method Side effects1 State updates2 Example uses
Mounting
componentWillMount Constructor equivalent for createClass
render Create and return element(s)
componentDidMount DOM manipulations, network requests, etc.
Updating
componentWillReceiveProps Update state based on changed props
@ianstormtaylor
ianstormtaylor / slate-node-portal.js
Created September 13, 2016 18:21
A React component example that makes it simple to position an element relative to a Slate node.
import React from 'react'
import Portal from 'react-portal'
import getOffsets from 'positions'
import { findDOMNode } from 'slate'
/**
* No-op.
*
* @type {Function}
@sineed
sineed / ams.rb
Last active June 10, 2020 15:42
Upgrade AMS from 0.9.0 to 0.10.0
module AMS
module V09
class Serializer < ActiveModel::Serializer
def serializable_hash(adapter_options = nil,
options = {},
adapter_instance = self.class.serialization_adapter_instance)
object.nil? ? nil : super
end
end
import React from 'react'
import Portal from 'react-portal'
class LinkBlock extends React.Component {
constructor (props) {
super(props)
this.state = {
href: this.props.node.data.get('href'),
showingPopup: false,
popup: null,
@andrewmclagan
andrewmclagan / actions.js
Last active March 12, 2023 12:23
react-redux-universal-hot-example
export function login(loginHandle, password) {
return {
types: [LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE],
promise: (api) => api.post('/auth/login', { login: loginHandle, password }).then(response => {
setAuthCookie(response.token); // side effect pre success dispatch
return response;
}),
then: (response) => {
postLoginRedirect(browserHistory.push, response.user, response.organisation); // side effect post success dispatch
},
@andrewmclagan
andrewmclagan / Dockerfile
Created February 9, 2016 23:37
react-redux-universal-hot-example Sample Dockerfile with AWS S3 static asset upload
FROM node:5.1.1
#Install AWS CLI
RUN apt-get update
RUN apt-get install -y python-pip
RUN pip install awscli
RUN mkdir -p /root/.aws
RUN echo '[default]' > /root/.aws/config
RUN echo 'output = json' >> /root/.aws/config
RUN echo 'region = us-east-1' >> /root/.aws/config
@brianhempel
brianhempel / bench_rails_memory_usage.rb
Last active October 6, 2022 12:47
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0