Skip to content

Instantly share code, notes, and snippets.

View rajaraodv's full-sized avatar

Raja Rao DV rajaraodv

View GitHub Profile
{
"name": "Default color scheme for shell prompts",
"groups": {
"hostname": { "fg": "brightyellow", "bg": "mediumorange", "attrs": [] },
"environment": { "fg": "white", "bg": "darkestgreen", "attrs": [] },
"mode": { "fg": "darkestgreen", "bg": "brightgreen", "attrs": ["bold"] },
"attached_clients": { "fg": "white", "bg": "darkestgreen", "attrs": [] },
"gitstatus": { "fg": "gray8", "bg": "gray2", "attrs": [] },
"gitstatus_branch": { "fg": "gray8", "bg": "gray2", "attrs": [] },
@rajaraodv
rajaraodv / TicTacToeReact.js
Created October 15, 2017 23:22
React's version of TicTacToe
function Square(props) {
return (
<button className="square" onClick={props.onClick}>
{props.value}
</button>
);
}
class Board extends React.Component {
renderSquare(i) {
@rajaraodv
rajaraodv / TicTacToeHyperapp.js
Last active October 15, 2017 23:23
Hyperapp version of TicTacToe app
const { h, app } = hyperapp;
/** @jsx h */
function Square(props) {
return (
<button class="square" onclick={props.onClick}>
{props.value}
</button>
);
}
@rajaraodv
rajaraodv / verify-jwt.js
Created November 30, 2016 14:50
verify jwt in app.js
//https://github.com/rajaraodv/react-redux-blog/blob/master/app.js#L41-L63
//middleware that checks if JWT token exists and verifies it if it does exist.
//In all the future routes, this helps to know if the request is authenticated or not.
app.use(function(req, res, next) {
// check header or url parameters or post parameters for token
var token = req.headers['authorization'];
if (!token) return next(); //if no token, continue
token = token.replace('Bearer ', '');
const Validation = require('data.validation') //from folktalejs
const Success = Validation.Success
const Failure = Validation.Failure
const R = require('ramda');
function isUsernameValid(a) {
return /^(0|[1-9][0-9]*)$/.test(a) ? Failure(["Username can't be a number"]) : Success(a)
}
function isPwdLengthCorrect(a) {
const tax = R.curry((tax, price) => {
if (!_.isNumber(price)) return Left(new Error("Price must be numeric"));
return  Right(price + (tax * price));
});
const discount = R.curry((dis, price) => {
if (!_.isNumber(price)) return Left(new Error("Price must be numeric"));
var Either = require('ramda-fantasy').Either;
var Left = Either.Left;
var Right = Either.Right;
const tax = R.curry((tax, price) => {
if (!_.isNumber(price)) return Left(new Error("Price must be numeric")); //<--Wrap Error in Either.Left
return  Right(price + (tax * price)); //<--Wrap result in Either.Right
});
//imperative
//Returns error or price including tax
const tax = (tax, price) => {
if (!_.isNumber(price)) return new Error("Price must be numeric");
return price + (tax * price);
};
//Returns error or price indluding discount
const discount = (dis, price) => {
class Maybe {
constructor(val) {
this.val = val;
}
...
...
//"ap" takes another "maybe" and applies the function it's holding in itself.
//this.val MUST be a function or Nothing (and can't be some string or int)
ap(differentMayBe) {
@rajaraodv
rajaraodv / currying-example.js
Last active November 18, 2016 23:16
The below gist shows how to take care of global variables and also make funcs chainable
//The below gist shows how to take care of global variables and also make funcs chainable
//Global indexURLs map for different languages
let indexURLs = {
'en': 'http://mysite.com/en', //English
'sp': 'http://mysite.com/sp', //Spanish
'jp': 'http://mysite.com/jp' //Japanese
}
//Imperative