Skip to content

Instantly share code, notes, and snippets.

View rahul-dhar-e5609's full-sized avatar
🎧
Calm while Coding

Rahul Dhar rahul-dhar-e5609

🎧
Calm while Coding
View GitHub Profile
@rahul-dhar-e5609
rahul-dhar-e5609 / Pig
Created January 3, 2019 17:17
A game of pig in golang
package main
import (
"fmt"
"math/rand"
)
const (
win = 100 //The winning score
gamesPerSeries = 10 //The number of games per series to simulate
@rahul-dhar-e5609
rahul-dhar-e5609 / hooks.js
Last active May 15, 2019 13:53
Wordpress like hook system for javascript. A library that makes code extensible by using hooks like in the Wordpress CMS.
/**
*
* Wordpress like hook system for javascript.
*
* The purpose of this library is to make code extensible by using hooks like in
* the Wordpress CMS.
*
* The functions in this library shall help other developers hook their code
* into a generic code using their callbacks.
*
import React, { Component } from 'react';
import { connect } from 'react-redux';
export default function (ComposedComponent) {
class Authentication extends Component {
// static -> class level property
//eg. Authentication.contextType
static contextTypes = {
// if we want access to our router
// we need to say ahead of time that
import {
CHANGE_AUTH
} from '../actions/types';
//for auth reducer the default state is false
//i.e. user is not logged in
export default function (state = false, action){
switch (action.type){
case CHANGE_AUTH:
return action.payload;
import {
CHANGE_AUTH
} from './types';
export function authenticate (isLoggedIn) {
return {
type: CHANGE_AUTH,
payload: isLoggedIn
};
}
@rahul-dhar-e5609
rahul-dhar-e5609 / index.js
Created April 20, 2018 04:32
This is index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import { Router, Route, browserHistory } from 'react-router';
import App from './components/app';
import Resources from './components/resources';
import reducers from './reducers';
const createStoreWithMiddleware = applyMiddleware()(createStore);