Skip to content

Instantly share code, notes, and snippets.

@jtlindsey
jtlindsey / systemd_nodejs_express_app_example.txt
Last active May 16, 2017 01:02
Running a nodejs expressjs application on linux with systemd
# place file in following location
/etc/systemd/system/<application name>.service
[Unit]
Description=<application Name>
After=mongodb.service # Example that Requires the mongod service to run first
[Service]
# make sure to run the following as a regular user so node is found after each node upgrade
# n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
@jtlindsey
jtlindsey / login.js
Last active March 24, 2017 17:04 — forked from sammylupt/login.js
/*
from
https://medium.com/the-many/adding-login-and-authentication-sections-to-your-react-or-react-native-app-7767fd251bd1#.z5fpuv78y
*/
function loggedIn() {
// ...
}
@jtlindsey
jtlindsey / ServerSide.js
Created March 22, 2017 14:58
Thinking about reactjs serverside
router.get('*', function(request, response) {
let initialState = { title: 'Universal React' };
let store = Redux.createStore(reducer, initialState);
ReactRouter.match({
routes: require('./routes'),
location: request.url
}, function(error, redirectLocation, renderProps) {
if (!USER_LOGGED_IN) {
let html = ReactDOMServer.renderToString(
@jtlindsey
jtlindsey / .bashrc
Last active March 17, 2017 02:52
My command line prompts for .bashrc
#my prompt in lightblue/yellow [user@hostname$]
export PS1="\[\033[1;33m\][\[$(tput sgr0)\]\[\033[1;36m\]\u\[$(tput sgr0)\]\[\033[1;33m\]@\h\[$(tput sgr0)\]\[\033[1;37m\]\\$\[$(tput sgr0)\]\[\033[1;33m\]]\[$(tput sgr0)\]\[\033[1;33m\] \[$(tput sgr0)\]"
#add timestamps to history
export HISTTIMEFORMAT="%d/%m/%y %T "
#root prompt in lightblue/red [user@hostname#] (put this in .bashrc of root)
export PS1="\[\033[1;31m\][\[$(tput sgr0)\]\[\033[1;36m\]\u\[$(tput sgr0)\]\[\033[1;31m\]@\h\[$(tput sgr0)\]\[\033[1;37m\]\\$\[$(tput sgr0)\]\[\033[1;31m\]]\[$(tput sgr0)\]\[\033[1;31m\] \[$(tput sgr0)\]"
@jtlindsey
jtlindsey / looper.js
Last active March 16, 2017 13:10
Pass any function and its arguments using rest parameter syntax to function that repeats that function.
/*
Sometimes i wan to run different functions multiple times without re-writing setInterval
and specifying speed, etc. This solution made that a little quicker.
*/
const looper = (runCount, i, speed, logit, fn, ...args) => {
let r = () => {
if (i++ >= runCount) {clearTimeout(si)};
logit ? console.log(fn(...args)) : fn(...args);
};
let si = setInterval(r, speed);
@jtlindsey
jtlindsey / text_randomizer.js
Created March 15, 2017 21:43
Text randomizer
/*
I needed to convert many values in thousands of records in multiple relational collections to
non-recognizable random strings. This way I could still use private DB records to populate a database for
a demo application without compromizing privacy or security. Rather than create a function to create thousands
of random records with connected relations, or replace each value with a random word from an array of strings,
I passed each value through this function before populating the record in the demo database.
It removes all spaces, splits the characters into an array, sorts alphabetically, grabs a random position
in the array of letters, assigns a random string based on a random Unicode value from 1-50, assigns that