Skip to content

Instantly share code, notes, and snippets.

Avatar

Travis Lindsey jtlindsey

View GitHub Profile
@jtlindsey
jtlindsey / systemd_nodejs_express_app_example.txt
Last active May 16, 2017
Running a nodejs expressjs application on linux with systemd
View systemd_nodejs_express_app_example.txt
# 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
View 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 Mar 22, 2017
Thinking about reactjs serverside
View ServerSide.js
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 Mar 17, 2017
My command line prompts for .bashrc
View .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 Mar 16, 2017
Pass any function and its arguments using rest parameter syntax to function that repeats that function.
View looper.js
/*
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);
View text_randomizer.js
/*
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
You can’t perform that action at this time.