Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamis Charles jamischarles

View GitHub Profile
View closure-experiments.js
// weirdness with closures
// Setup: pass an obj to a function, and then another function (in my case apollo server)
// Test: the thing is executed, then I change the object, then execute again. What is the object value passed in?
var mockReqObj = { test: 'jamis' };
// Variation 1)
// appears to use default value in console log (for both)
mockReqObj = { test: 'NBODOy' };
View gist:015d1091edb0445a642fa65866ef3978
###############################################################################
# byobu's tmux f-key keybindings
#
# Copyright (C) 2011-2014 Dustin Kirkland <kirkland@byobu.co>
#
# Authors: Dustin Kirkland <kirkland@byobu.co>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
@jamischarles
jamischarles / proud.md
Last active Oct 27, 2020
Things I'm most proud of
View proud.md
View nodejs_express_file-structure.markdown

consider making a node-guides site like rails guides?

Approach 1:

TJ HollowayChuck (creator of Express)

"personally I find large rails-style structure difficult to work with for large applications (great for small ones however). A more modular approach like Drupal is a big win as far as management goes but it can complicate some things (layout templates) so you kind of need

@jamischarles
jamischarles / react-i18n.js
Created Oct 23, 2020
Examples of how to interpolate strings in React with elements (useful for i18n)
View react-i18n.js
// More modern version of what's found here by Khan academy: https://github.com/martinandert/react-interpolate-component/blob/master/index.js
// 1) simple way to result in <div>Hello</div>
let a = React.createElement("div", null, "Hello");
// 2) Create a fragment instead of a div so you can pass in JSX as one of the children. Key is optional I think
// <Fragment key="0">Hello my friend, <a href="http://www.cnn.com">This is good</a> </Fragment>
let b = React.createElement(
React.Fragment, {key: 0},
"hello my friend ",
@jamischarles
jamischarles / Sci-fi.txt
Last active Oct 5, 2020
Best books I've read
View Sci-fi.txt
## Military Scifi:
-Expeditionary Force Series
-Galaxy's Edge Series
## Unique Scifi
-Skyward (Top Gun in space)
-Bobiverse Series
-Enders Game (re-read this every few years)
-Murderbot Diaries Series (really great)
-Artemis (Andy Weir)
@jamischarles
jamischarles / sanitize_json.js
Created Jun 25, 2011
JavaScript: Sanitize JSON string before saving, so it can be read again. (Escapes newlines etc)
View sanitize_json.js
function sanitizeJSON(unsanitized){
return unsanitized.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\f/g, "\\f").replace(/"/g,"\\\"").replace(/'/g,"\\\'").replace(/\&/g, "\\&");
}
@jamischarles
jamischarles / get.js
Last active Jan 8, 2020
Rebuilding simple version of _.get()
View get.js
function get(base, pathQuery, returnOnUndefinedValue) {
var pathArr = pathQuery.split('.');
var currentVal = base;
for (var i=0; i<pathArr.length; i++) {
var key = pathArr[i];
currentVal = currentVal[key];
if (!currentVal) {
return returnOnUndefinedValue ;
}
}
View git_commands.sh
- my normal flow?
- good commit messages ******
- searching commit messages (group by keywords)
- searching code *
- working with history (viewing, time traveling)
- rebasing (for pulling & squashing, splitting a commit) *
- undoing local commits (soft, hard reset)
- forgot to add / change message (amend)
- LOST commits? *
@jamischarles
jamischarles / gitmove.sh
Last active Feb 21, 2019
Git move - Move file to new repo and preserve history
View gitmove.sh
#!/bin/bash
# $ ./gitmove [destGitRepo] [src_file]
DEST_FOLDER=$1
SOURCE_FILE=$2
# get the earliest hash of a source file to copy
HASH=$(git log --format=%H $SOURCE_FILE | tail -1)
# echo $HASH