Skip to content

Instantly share code, notes, and snippets.

class Vehicle
def initialize(args)
@color = args[:color]
@wheels = args[:wheels]
end
def drive
if crash
@status = :crashed
else
@anirudh-eka
anirudh-eka / index.html
Last active December 20, 2015 20:29 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
@anirudh-eka
anirudh-eka / form-validator.js
Last active December 21, 2015 03:58 — forked from ksolo/form-validator.js
Form Validation
// shorthand for $(document).ready();
$(function(){
$('form').on('submit', function(e){
e.preventDefault();
var email_regex = new RegExp("[a-zA-Z]+[@][a-zA-Z]+[.][a-z]{2,}");
var email_input = $('input[type=text]').val();
var email_match = email_regex.test(email_input);
if (email_match == false){
@anirudh-eka
anirudh-eka / MethodSignitureForFold.hs
Created April 8, 2018 07:22
A method Signature for fold in Haskell
(a -> Bool) -> [a] -> [a]
@anirudh-eka
anirudh-eka / sumWithFold.hs
Created April 8, 2018 07:32
Function that adds all items in a list
sum ns = foldl (+) 0 ns
sum([1,2,3]) -- returns 6
@anirudh-eka
anirudh-eka / filterWithFoldl.hs
Created April 8, 2018 07:34
Filter implemented with foldl
filter' :: (a -> Bool) -> [a] -> [a]
filter' f as = foldl (\bs -> (\a -> if f a then bs ++ [a] else bs))[] as
@anirudh-eka
anirudh-eka / mapWithFoldl.hs
Created April 8, 2018 07:34
Map implemented with foldl
map'' :: (a -> b) -> [a] -> [b]
map'' f as = foldl (\bs a -> bs ++ [f a]) [] as
@anirudh-eka
anirudh-eka / appendReducer.js
Last active April 28, 2018 09:56
A tool that allows one Redux reducer to delegate reducer logic for a portion of it's state to another reducer
import zipObj from 'ramda/src/zipObj';
export function appendReducer(coreReducer, additionalReducers) {
return (state, action) => {
const newState = coreReducer(state, action);
const keys = Object.keys(additionalReducers);
const reducedValues = keys.map(k => additionalReducers[k](newState[k], action));
return {...newState, ...zipObj(keys, reducedValues)};
};
@anirudh-eka
anirudh-eka / mapObj.js
Last active June 1, 2018 22:34
A simple implementation of map function for an object
function mapObj(fn, obj) {
var keys = Object.keys(obj)
var newObj = {}
for(var i = 0; i < keys.length; i++) {
newObj[keys[i]] = fn(obj[keys[i]]);
}
return newObj
}