Skip to content

Instantly share code, notes, and snippets.

View jamischarles's full-sized avatar

Jamis Charles jamischarles

View GitHub Profile
@jamischarles
jamischarles / inlineJS.ts
Created April 16, 2024 18:51
Inline JS into the dom. Careful. ensure you're running this through a build step of some sort to avoid browser errors
/**
* Stringifies a function, and wraps it in an IIFE so it'll auto execute.
* @remarks The assumption is that you'll be inlining this function into a vanilla \<script\> tag on the page.
* Therefore you should follow these rules:
* Standalone code. No imports / or deps on other files / methods.
* You can use TS, but carefully watch how the output is compiled down to ensure it works for the lowest browser target.
* Ensure safety. Anything that can fail should likely be wrapped in a try/catch.
* This will likely be used as blocking js. Keep it short!
* @param parameter1 - Allows passing a 1/2 string|number param to the function to be inlined.
* @param parameter2 - Allows passing a 2/2 string|number param to the function to be inlined.
@jamischarles
jamischarles / sanitize_json.js
Created June 25, 2011 17:12
JavaScript: Sanitize JSON string before saving, so it can be read again. (Escapes newlines etc)
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 / Module 0: Pre-reqs.md
Last active April 29, 2023 05:22
Hardware / Arduino hacking True Beginner guide 101

Module 0: What you'll need to get started

Notes: Intro (All the cool stuff you can build)

M1 (should m1 be blinking light alone?) Then we reinforce it with each module…

#!/usr/bin/env bash #adding this to force silly gist highlighting. REMOVE THIS
# This is a modified version of the script generated by https://docs.npmjs.com/cli/completion to include `npm install` autocompletion.
# Basically we added `if` blocks to check for `install` subcommand.
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
@jamischarles
jamischarles / nodejs_express_file-structure.markdown
Created July 17, 2012 20:35
Node.js file structure with express

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 / Anime_Cartoon shows.txt
Last active October 5, 2021 06:01
Best books I've read
Legend of Korra
Dragon Prince
Trollhunters
@jamischarles
jamischarles / closure-experiments.js
Created January 28, 2021 19:02
Closure experiments
// 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' };
###############################################################################
# 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 October 27, 2020 21:19
Things I'm most proud of
@jamischarles
jamischarles / react-i18n.js
Created October 23, 2020 23:51
Examples of how to interpolate strings in React with elements (useful for i18n)
// 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 ",