Skip to content

Instantly share code, notes, and snippets.

View marg51's full-sized avatar
🎯
Focusing

Laurent M marg51

🎯
Focusing
View GitHub Profile
@marg51
marg51 / app.js
Created September 10, 2016 14:33
List all URLs of your app from ui-router
app.run( ($state) => {
const indexed_state = {}
const states = $state.get()
states.forEach( state => {
indexed_state[ state.name ] = state
})
const URLs = states.map( state => getUrlOf(state) )
wage() {
curl -s -XPOST 'http://www.thesalarycalculator.co.uk/salary.php' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Connection: keep-alive' --data "salary=$1&age=low&taxcode=&bonus=&payperiod=12&otime1=&orate1=1.5&otime2=&orate2=2&pensiontype=employer&pension=&childcare=&sacrifice=&sacrificeperiod=12&taxablebenefits=&benefitperiod=12&pretax=&posttax=&chosenTaxYear=2016&submit=Go%21&timeperiods%5B%5D=1&timeperiods%5B%5D=12&timeperiods%5B%5D=52&timeperiods%5B%5D=260&submit=" | pup '.takehome td:nth-child(3) text{}'
}
# `source .aliases`
class App extends Component {
componentDidMount() {
this.refs.nav.navigator.navigationContext.addListener("willfocus", () => {
// do something smart, ie. close all modals, update your redux state, whatever
})
}
render() {
return (
<View style={styles.container}>
<NavigatorIOS
@marg51
marg51 / react-redux-without-decorators.js
Last active January 22, 2017 13:35
Medium — Decorators
// example from http://redux.js.org/docs/basics/UsageWithReact.html
// annotated and simplified for this Medium story
import { connect } from 'react-redux'
import TodoList from "./todo-list"
const mapStateToProps = (state) => {
return {
todos: state.todos // bound to `this.props.todos`
}
@marg51
marg51 / connect-step1.js
Created January 22, 2017 13:36
medium — react-redux
function connect(mapStateToProps, mapDispatchToProps) {
// Target is a component, TodoList in our example
return Target => {
// do something with it
}
}
@marg51
marg51 / connect-step2.js
Created January 22, 2017 16:58
medium — connect
function connect(mapStateToProps, mapDispatchToProps) {
return (Target) => {
// we need to return a class
class Connected extends Component {
render() {
return <Target />
}
}
import TodoList from "./todo-list"
function connect(mapStateToProps, mapDispatchToProps) {
return (Target) => {
class Connected extends Component {
render() {
// we pass the props down
return (<Target {...this.props} />)
}
function compose(composeFn, param) {
if(typeof composeFn != "function")
return {}
return composeFn(param)
}
function connectProps(store, mapStateToProps, mapDispatchToProps) {
return {
...compose(mapStateToProps, store.getState()),
@marg51
marg51 / log.js
Created January 26, 2017 12:25
Logger
require("colors")
exports.createLogger = (type) => ({
log: (...args) => console.log(`[${type}]`.gray, ...args),
warn: (...args) => console.log(`[${type}]`.cyan, ...args),
error: (...args) => console.log(`[${type}]`.red, ...args),
success: (...args) => console.log(`[${type}]`.green, ...args)
})
@marg51
marg51 / App.jsx
Last active February 4, 2017 13:14
ng-repeat with inferno / react
import Inferno from 'inferno';
import Component from 'inferno-component';
import './App.css';
import Repeater from "./Repeater"
import DisplayProps from "./DisplayProps"
class App extends Component {
constructor(props) {
super(props)