Skip to content

Instantly share code, notes, and snippets.

Jernej Sila JSila

Block or report user

Report or block JSila

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JSila
JSila / router.js
Created Apr 23, 2018
custom router solution for react (experiment)
View router.js
import React, {Component, createElement} from 'react'
import createHistory from 'history/createBrowserHistory'
import classnames from "classnames"
export const history = createHistory()
/**
* Determines if route path matches history location's pathname. If it does, extracts its params. If not, returns null.
*
* @param routePath
@JSila
JSila / withForm-1.js
Last active Apr 30, 2018
withForm higher-order component
View withForm-1.js
import React from "react"
const noop = () => false
const withForm = (fields, validateFn = noop, validSubmitFn) => WrappedComponent => {
class WithForm extends React.Component {
constructor(props) {
super(props)
this.state = {
@JSila
JSila / index.js
Created Mar 4, 2018
Helpers for providing and consuming multiple react contexts
View index.js
import React, {Component} from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import createContext from 'create-react-context'
const Theme = createContext("light")
const Language = createContext("en")
const Whatever = createContext("whatever")
@JSila
JSila / client.go
Last active Oct 4, 2017
Context cancelation example in Go
View client.go
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"net/http"
"time"
)
@JSila
JSila / middleware.go
Last active Jul 4, 2017
JSON schema middleware and valide helpers for Go
View middleware.go
import (
"context"
"net/http"
"github.com/Sirupsen/logrus"
"github.com/matryer/respond"
)
func CheckJSON(log *logrus.Logger, h http.Handler, data interface{}, contextKey string) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@JSila
JSila / WP_Settings.php
Last active Sep 2, 2019
WP Settings API in OOP way
View WP_Settings.php
<?php
class WP_Settings_Section {
protected $id = '';
protected $title = '';
protected $output_callback = '';
protected $fields = array();
public function __construct($id, $title, $output_callback) {
$this->id = $id;
@JSila
JSila / unsbscribe.js
Last active Jan 28, 2017
higher order function for react that auto-unsubscribes from RxJS Observables on componentWillUnmount
View unsbscribe.js
import React, {Component} from 'react'
import forEach from 'lodash/forEach'
export default () => ComposedComponent => class extends Component {
subscriptions = {}
componentWillUnmount() {
forEach(this.subscriptions, subscription => {
subscription.unsubscribe()
})
}
@JSila
JSila / App.js
Created Jan 12, 2017
Example of showing/hiding Twitter Bootstrap (4) modal - with react, not jquery
View App.js
import React, { Component } from 'react'
import Modal from './Modal'
export default class extends Component {
constructor(props) {
super(props)
this.state = {
isOpen: false
@JSila
JSila / FormGroup.js
Last active Dec 19, 2016
Highly reusable FormGroup React stateless component with Twitter Bootstrap 4 specific CSS classes
View FormGroup.js
import React, {PropTypes} from 'react'
import classnames from 'classnames'
import setDisplayName from 'recompose/setDisplayName'
import getDisplayName from 'recompose/getDisplayName'
import defaultProps from 'recompose/defaultProps'
import compose from 'recompose/compose'
import setPropTypes from 'recompose/setPropTypes'
const FormGroup = ({name, label, error, inputType}) => {
const el = React.createElement(inputType, {
You can’t perform that action at this time.