Skip to content

Instantly share code, notes, and snippets.

View kevgathuku's full-sized avatar

Kevin Gathuku kevgathuku

View GitHub Profile
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
}
@kevgathuku
kevgathuku / docker_kill.sh
Created February 13, 2018 09:43 — forked from evanscottgray/docker_kill.sh
kill all docker containers at once...
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt
@kevgathuku
kevgathuku / uuid_url64.py
Created February 7, 2018 11:55 — forked from mattupstate/uuid_url64.py
Generate unique, URL friendly ID's based on UUID with Python
import re
import uuid
import base64
def uuid_url64():
"""Returns a unique, 16 byte, URL safe ID by combining UUID and Base64
"""
rv = base64.b64encode(uuid.uuid4().bytes).decode('utf-8')
return re.sub(r'[\=\+\/]', lambda m: {'+': '-', '/': '_', '=': ''}[m.group(0)], rv)
object Main {
def main(args: Array[String]): Unit =
println("Hello, Scala developer!")
}