Skip to content

Instantly share code, notes, and snippets.

var myURL="mydomain.com";
var restifyOptions={}
restifyOptions.certificate = fs.readFileSync('PathTo:fullchain.pem');
restifyOptions.key = fs.readFileSync('PathTo:privkey.pem');
var server = restify.createServer(restifyOptions);
var nonSecure = restify.createServer({name: 'redirectToSSL'});
nonSecure.get(/.*/,function (req, res, next) {
res.redirect(301, 'https://' + myURL + req._url.href, next);
var _putItem = function (item, shouldCreateNewItem, shouldReturnInformationFromJoinedTable) {
return knex(...).update()
.then(function(affectedRows) {
if (affectedRows == 0 && shouldCreateNewItem) return knex.insert(...);
else if (shouldReturnInformationFromJoinedTable) return knex(...). ....leftJoin(..).select().first()
else return true;
})
}
@avimar
avimar / getRegion.js
Last active September 15, 2016 04:20
north-america-area-codes
var NorthAmerica=require('./NorthAmerica.json');
var fp = require('lodash/fp');
function getRegionForAreaCode(areaCode){
return fp.findKey(function(o) {
return o.includes(areaCode);
})(NorthAmerica);
}
@avimar
avimar / build.sls
Created August 8, 2012 19:04
FreeSWITCH Salt install file
freeswitch-build:
pkg:
- installed
- names:
- build-essential
- curl
- wget
- autoconf
- automake
- libtool

Keybase proof

I hereby claim:

  • I am avimar on github.
  • I am avimarcus (https://keybase.io/avimarcus) on keybase.
  • I have a public key whose fingerprint is 1AFA CC40 32FD 2FE9 BCE3 88FE D5DD 1501 34E0 ABD8

To claim this, I am signing this object:

@avimar
avimar / gist:16824955e21781c7e2c6594ef743bc6f
Created February 17, 2017 06:09
innodb not optimizing?
`show create table logs_fs`
CREATE TABLE `logs_fs` (
`uuid` char(36) DEFAULT NULL,
`host` varchar(4) DEFAULT NULL,
`date` datetime(6) NOT NULL,
`hrtime` bigint(20) unsigned NOT NULL,
`level` tinyint(4) DEFAULT NULL,
`value` text,
KEY `uuid` (`uuid`),
@avimar
avimar / README.md
Last active July 1, 2017 14:13
Node.js/Javascript Stack

Programming Environment:

node.js backend:

  • nconf: loadable, pluggable configuration
  • restify: instead of express, it's oriented for APIs
  • bunyan: for logging, built in support from restify
  • knex.js: SQL query builder/promises/pooling (but it's not an ORM)
  • PM2: deploy and clustering
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@avimar
avimar / 1.txt
Last active February 26, 2018 16:07
testing window.open prevention
Sample file.
@avimar
avimar / index.js
Created February 15, 2019 08:03
FreeSWITCH de-register monitor
#! /usr/bin/node
var nodemailer = require("nodemailer");
var transport = nodemailer.createTransport("sendmail");
function fix_len(num, len){
if(len<=5) return ("00000" + num).slice(-len);
else {
var seed="0000000000";
while(seed.length<len) seed+=seed;