Skip to content

Instantly share code, notes, and snippets.

@JSila
JSila / middleware.go
Last active July 4, 2017 09:27
JSON schema middleware and valide helpers for 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 / unsbscribe.js
Last active January 28, 2017 13:20
higher order function for react that auto-unsubscribes from RxJS Observables on componentWillUnmount
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 / FormGroup.js
Last active December 19, 2016 20:28
Highly reusable FormGroup React stateless component with Twitter Bootstrap 4 specific CSS classes
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, {
@JSila
JSila / output.bash
Created September 20, 2016 21:55
error using html-webpack-plugin with extract-text-webpack-plugin
➜ when-i-tweet git:(master) npm start
> when-person-tweets@1.0.0 start /home/jernej/Code/when-i-tweet
> nodemon --ignore ./src
[nodemon] 1.10.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
Running on http://localhost:3000
@JSila
JSila / karma.config.js
Created September 8, 2016 20:24
karma test runner example (with webpack)
var webpackConfig = require('./webpack.config')
webpackConfig.entry = undefined
module.exports = function (config) {
config.set({
browsers: ['Chrome'],
files: [
'tests.webpack.js' // karma only needs to know where test files are. if you include source files, you are gonna have a bad time.
],
frameworks: ['mocha'],
@JSila
JSila / index.html
Created September 8, 2016 20:18
browser test runner example (mocha, chai, sinon withjquery)
<!DOCTYPE html>
<html>
<head>
<title>Mocha Tests</title>
<link rel="stylesheet" href="/node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="https://code.jquery.com/jquery.min.js"></script>
@JSila
JSila / embed-codes.html
Created June 13, 2016 21:05
Embed codes of some popular social networks
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Embedding</title>
</head>
<body>
<!-- facebook -->
<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fpolygon%2Fposts%2F1207194309293195&width=500" width="500" height="482" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>
@JSila
JSila / clean-public.js
Last active April 14, 2016 21:44
gulpfile.js for developing applications in React with ES6
module.exports = (gulp, del, paths) => {
gulp.task('clean-public', () => {
return del([ paths.jsPublicFiles, paths.jsSourceMaps ]);
});
};
@JSila
JSila / cool-js-libs.md
Last active April 7, 2016 13:35
JavaScript libraries that I discovered and deserves a special mention.
  • FlightJS: A component-based, event-driven JavaScript framework built on top of jQuery. From Twitter.
  • React: A declarative, efficient, and flexible JavaScript library for building user interfaces. Developed and used by Facebook and Instagram.
  • Redux: Predictable state container for JavaScript application.
  • stampit: Create objects from reusable, composable behaviors. Stampit uses three different kinds of prototypal OO to let you inherit behavior in a way that is much more powerful and flexible than classical OO.
  • unexpected-react: Extension for unexpected assertion library to make testing React components easier.