Skip to content

Instantly share code, notes, and snippets.

View yosevu's full-sized avatar

Yosevu Kilonzo yosevu

View GitHub Profile
@yosevu
yosevu / sudoku-validator.js
Created February 27, 2019 13:59
sudoku-validator
function getIndex(i) {
return Math.floor(i / 3);
}
function fillArray(len, item) {
return new Array(len).fill(item);
}
function isValid(totals) {
const result = Object.values(totals).every(total => {
@yosevu
yosevu / 01-directory-structure.md
Created January 27, 2019 21:20 — forked from tracker1/01-directory-structure.md
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.

Directories

  • lib/ is intended for code that can run as-is
  • src/ is intended for code that needs to be manipulated before it can be used
@yosevu
yosevu / export-git-log.txt
Created December 1, 2018 19:00
Export git log
git --no-pager log > log.txt
#
# Main prompt
#
# local host_name="%{$fg[cyan]%}λ"
local path_string="%{$fg[white]%}%1~"
local prompt_string="λ"
# Make prompt_string red if the previous command failed.
@yosevu
yosevu / entities.html
Last active December 1, 2018 18:14
Entities
<head>
<meta charset="utf-8">
<title>GitHub Pull Requests for Everyone</title>
<meta name="description" content="Writing good pull requests makes everyones life easier. Catherine shares how to set up successful code reviews with good pull requests.">
<meta property="og:title" content="GitHub Pull Requests for Everyone" />
<meta property="og:description" content="Writing good pull requests makes everyone&amp;apos;s everyone&#039;s life easier. Catherine shares how to set up successful code reviews with good pull requests." />
</head>
@yosevu
yosevu / bufferToBase64.js
Created July 1, 2018 03:27
Buffer to base64
const b = Buffer.from('hello, world');
console.log(b);
// <Buffer 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64>
const s = b.toString('base64');
console.log(s);
// aGVsbG8sIHdvcmxk
console.log(b.toString());
// hello, world
@yosevu
yosevu / change-screenshot-folder.md
Created June 26, 2018 18:52
change screenshot folder (macOS)

defaults write com.apple.screencapture location /Users/sparkuser/Pictures/Screenshots

@yosevu
yosevu / uploadImage.js
Last active June 18, 2018 19:04
Sails.js uploadImage helper
module.exports = {
friendlyName: 'Upload image',
description: 'Upload an image to AWS S3.',
inputs: {
req: {
type: 'ref',
example: 'req',
description: 'request object',
@yosevu
yosevu / kebabToCamel.js
Created June 8, 2018 16:22
Kebab to Camel Case
const replaceHyphens = string =>
string.replace(/(-\w)/g, m => m[1].toUpperCase());
const normalizeKeys = places => {
return Object.keys(places).reduce((nextPlaces, place) => {
const camelCaseName = replaceHyphens(place);
const currentPlace = places[place];
nextPlaces[camelCaseName] = Object.keys(currentPlace).reduce((nextPlace, prop) => {
const camelCaseProp = replaceHyphens(prop);
@yosevu
yosevu / placeHasManyReviews.js
Last active June 8, 2018 16:02
A place has many reviews
// https://sailsjs.com/documentation/concepts/models-and-orm/associations/one-to-many
// A place has many reviews
// api/models/Place.js
module.exports = {
attributes: {
// ...
reviews: {