Skip to content

Instantly share code, notes, and snippets.

View kevgathuku's full-sized avatar

Kevin Gathuku kevgathuku

View GitHub Profile
(defn compute-collatz [num steps]
(cond
(= num 1) steps
(even? num) (compute-collatz (/ num 2) (inc steps))
(odd? num) (compute-collatz (+ 1 (* num 3)) (inc steps))))
(defn collatz [num]
; Check if the provided number is positive. If not throw an error
(if
@kevgathuku
kevgathuku / EventComponent.spec.js
Created November 5, 2018 19:22 — forked from hartzis/EventComponent.spec.js
Touch Event Testing React Jest Enzyme
import React from 'react';
import EventComponent from './EventComponent';
import { mount } from 'enzyme';
import {
createStartTouchEventObject,
createMoveTouchEventObject
} from './EventHelpers.js';
describe('EventComponent', () => {
@kevgathuku
kevgathuku / Main.elm
Created October 1, 2018 16:37 — forked from sch/Main.elm
Minimum Elm boilerplate
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
type alias Model =
{ count : Int }
let arr = [];
for (var i = 0; i < 10; i++) {
arr.push(function() {console.log(i)});
}
let x = 0;
while (x < 10) {
arr[x]();
x++;
}

Mocking an imported function to return different values for different tests

In the top level:

import getVisibleDays from 'react-dates/lib/utils/getVisibleDays';

jest.mock('react-dates/lib/utils/getVisibleDays', () => {
  const moment = require('moment');
  return jest.fn().mockReturnValue({
 '2018-01': [
bundle exec rake db:drop db:create db:schema:load RAILS_ENV=test
@kevgathuku
kevgathuku / circleci-heroku-continuous-deployment2.0.md
Created August 5, 2018 18:26 — forked from lauraturk/circleci-heroku-continuous-deployment2.0.md
instructions for deploying from circleci2.0 to heroku

To get the npm cache folder, run npm config get cache

@kevgathuku
kevgathuku / sort.ex
Created June 18, 2018 10:37 — forked from rylev/sort.ex
Sort Algorithms in Elixir
## Sort Algorithms in Elixir
# Selection Sort
defmodule Selection do
def sort(list) when is_list(list) do
do_selection(list, [])
end
def do_selection([head|[]], acc) do
@kevgathuku
kevgathuku / api.js
Created May 23, 2018 19:53 — forked from pshoukry/api.js
React / Redux fetch from rails server with CSRF token
import _ from 'underscore';
import fetch from 'isomorphic-fetch'
class API {
getCSRFToken() {
return _.find(document.getElementsByTagName('meta'), (meta) => {
return meta.name === 'csrf-token'
}).content
}