Skip to content

Instantly share code, notes, and snippets.

@shotaK
shotaK / HOC.js
Last active May 29, 2020 14:30
React Higher Order Component with props validation.
import React, { Component, PropTypes } from 'React';
export const Enhance = ComposedComponent => {
class WrappedComponent extends Component {
attachFunction() {
ComposedComponent.attachFunction();
}
render() {
return <ComposedComponent {...this.props} additionalProps={this.state.additionalData} />;
}
@shotaK
shotaK / Adding Javascript code
Created December 23, 2016 10:00
Stackoverflow
<!-- language: lang-js -->
import React, {Component, PropTypes} from 'react';
import ChildComp from './child-comp';
class Comp extends Component {
render() {
const { Wrapper } = this.props;
return (
<Wrapper>
@shotaK
shotaK / click.js
Last active November 23, 2016 20:48
Redux - avoiding binding functions in constructor.
class MyComponent extends Component {
handleClick = (args) => (event) => {
// access args here;
// handle the click event
}
render() {
return (
<div onClick={this.handleClick(args)}>
.....
@shotaK
shotaK / data.js
Last active November 23, 2016 20:42
Redux Immutable JS
import {
ACTIVATE_LOCATION
} from './actions';
import Immutable from 'immutable';
let initialState = Immutable.Map([]);
export let ui = (state = initialState, action) => {
switch (action.type) {
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?";
@shotaK
shotaK / container.js
Created May 10, 2016 15:24
React/Redux Container Explanation
/**
* Created by shota on 5/10/16.
*/
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {selectBook} from '../actions/index';
import {bindActionCreators} from 'redux';
class BookList extends Component {
renderList() {
@shotaK
shotaK / destructuring.js
Created May 10, 2016 08:08 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
// DELETE specific rest resource
curl -v -X DELETE http://localhost:8080/api/components/country/3
// POST specific rest resource (id is generated automatically)
curl -i -X POST -H "Content-Type:application/json" http://localhost:8080/api/components/country -d '{"countryCode": "COW","countryName": "Cowland"}'
// PUT (update) specific rest resource
curl -i -X PUT -H "Content-Type:application/json" http://localhost:8080/api/components/country/5 -d '{"id": 5,"countryCode": "AS","countryName": "American COWA"}'
@shotaK
shotaK / Build Project
Last active November 26, 2015 12:09
Spring Boot
mvn package
@shotaK
shotaK / Env variables
Last active October 31, 2015 12:35
Tomcat
// Add CATALINA_HOME env variable
export CATALINA_HOME="/home/scabbard/programs/apache-tomcat-8.0.28"
// Make it permanent by adding the command to this file
sudo nano ~/.bashrc