Skip to content

Instantly share code, notes, and snippets.

View rvwhitney's full-sized avatar

Richard Whitney rvwhitney

View GitHub Profile
@rvwhitney
rvwhitney / add-and.js
Created September 27, 2023 22:13
When you have a comma separated list, and want to add an and before the last word
function removeLastComma(strng){
var n=strng.lastIndexOf(",");
var a=strng.substring(0,n)
return a;
}
function addAnd(strng){
var sp = strng.split(',');
sp.pop();
// log('splitting', sp)
@rvwhitney
rvwhitney / build-cluster.sh
Last active February 17, 2021 23:06
redis-cluster script for redis 6
#!/bin/bash
# this file assumes you have setup the config files on 3 different servers (6 config files)
# my sample a_master.conf: on server A
#------------------------------
# protected-mode no
# daemonize yes
# port 6379
# pidfile /var/run/redis_6379.pid
# logfile "redis6379.log"
# masterauth somemasterpass
@rvwhitney
rvwhitney / snippet1.js
Last active February 15, 2021 03:17
Show Line # the console.log is on for Node.js server
// can't remember where I got this but I did not write it:
// if app requires db.js
// place it in a required file, like db.js and the variable '__line__' will be available in app as well
// begin Object for __line__
Object.defineProperty(global, '__stack__', {
get: function(){
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
@rvwhitney
rvwhitney / like.js
Last active February 15, 2021 03:39
function like() for javascript
function like(haystack, needle) {
let n = -1;
if (typeof haystack !== 'object') {
let str = new String(haystack);
if (str !== "undefined") {
/// haystack = 'x';
/// needle = ['a','b','c','x'];
if (!Array.isArray(needle)) {
needle = [needle];