Skip to content

Instantly share code, notes, and snippets.

@kocisov
kocisov / index.js
Created May 1, 2017 16:09
sugar boi
// you can replace constructor with this
class Dashboard extends Component {
state = {
user: {}
}
componentDidMount() {...}
render() {...}
@kocisov
kocisov / containers_App.js
Last active April 30, 2017 21:15
Kocidux structure
// import react and router
import React, { Component } from 'react';
import { Route } from 'react-router-dom';
import Home from './Home'
export default class App extends Component {
render() {
return (
<div>
{/* this is how you add comments inside react render function -> jsx */}
@kocisov
kocisov / index.js
Created April 30, 2017 19:17
login
const USER_LOGGED_IN = '*/user/USER_LOGGED_IN'
const apiUrl = 'http://localhost:3000/api/login'
// If you haven't already installed redux-thunk middleware
// just do it LOL: https://github.com/gaearon/redux-thunk
// then doDis
function login ({ username, password }) {
return dispatch => {
fetch(`${apiUrl}`, {
method: 'POST',
function mapStateToProps (state) {
return {
user: state.user
}
}
// or
function mapStateToProps ({ user }) {
return {
user
@kocisov
kocisov / index.js
Last active April 30, 2017 16:45
redux215
// Component.js
import React from 'react'
// get props from redux store
export default ({ user, login }) =>
<div>
{!user.isAuthenticated ?
<div>
<button onClick={login}>
Login with StreamLabs
@kocisov
kocisov / index.js
Created April 22, 2017 09:23
emoteParserLUL
import parse from 'twitch-emoji';
import bttv from './bttv.json'; // https://api.betterttv.net/emotes
// it's a mess, just... don't... please... save us
function emoteParser (msg) {
let _msg = msg;
msg.split(/\s+/).map(t => {
bttv.emotes.filter(emote => t === emote.regex).map(e => {
if (e.url && e.url.length > 0) {
@kocisov
kocisov / index.css
Last active October 19, 2017 20:22
atom cc animation
@keyframes cc {
0% {
color: #fff;
}
10% {
color: #c92a2a;
}
20% {
@kocisov
kocisov / next_nginx.md
Last active February 3, 2025 07:27
How to setup next.js app on nginx with letsencrypt
@kocisov
kocisov / index.js
Created March 15, 2017 21:03
Entry file
import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { syncHistoryWithStore } from 'react-router-redux'
import store from './store'
import {
Router,
Route,
IndexRoute,
@kocisov
kocisov / user.js
Created March 15, 2017 20:52
User reducer
const CHANGE = '.../user/CHANGE'
export default function user (state = {
name: 'Koci',
avatar: '//placecage.com/200/200',
rank_group: 5,
points: 1341
}, action) {
switch (action.type) {
case CHANGE: