Skip to content

Instantly share code, notes, and snippets.

@velizarn
velizarn / dbUtils.js
Last active December 31, 2017 16:26
How to reuse mongodb connection through Promise
'use strict'
const assert = require('assert')
module.exports = {
getProductsCount: (req, res) => {
return new Promise((resolve, reject) => {
const crypto = require('crypto'), https = require('https')
// --------------------------------------------------------------------
let setString = (str = '') => {
return new Promise((resolve, reject) => {
let _name = str || 'John Doe';
@velizarn
velizarn / promise.js
Last active December 28, 2017 07:38
JavaScript basic Promise example
let getName = () => {
return new Promise((resolve, reject) => {
let name = "John Doe";
try {
setTimeout (() => {
resolve( name )
}, 1500)
@velizarn
velizarn / sendgrid.bash
Last active March 12, 2024 13:13
Send email from bash script by using SendGrid API
#!/bin/bash
SENDGRID_API_KEY=""
EMAIL_TO=""
FROM_EMAIL=""
FROM_NAME=""
SUBJECT=""
bodyHTML="<p>Email body goes here</p>"
@velizarn
velizarn / iptables-custom-log.bash
Last active January 18, 2017 17:50
Log iptables messages in a custom file with rsyslog
#!/bin/bash
IPTABLES_CONF_FILE=/etc/rsyslog.d/iptables.conf
echo ':msg, contains, ": IPTables Packet Dropped: " /var/log/iptables.log' > $IPTABLES_CONF_FILE
echo ':msg, contains, ": IPTables Packet Dropped: " ~' >> $IPTABLES_CONF_FILE
systemctl restart rsyslog
# http://blog.stalkr.net/2009/10/logging-iptables-messages-with-rsyslog.html
@velizarn
velizarn / ip6tables_setup.bash
Last active March 27, 2024 21:48
Basic setup for ip6tables - drop all traffic except local, ICMP and DHCPv6 traffic.
#!/bin/bash
# http://serverfault.com/questions/410321/debian-ip6tables-rules-setup-for-ipv6/410327#410327
# http://ipset.netfilter.org/iptables.man.html
# https://www.sixxs.net/wiki/IPv6_Firewalling
# https://www.cyberciti.biz/faq/ip6tables-ipv6-firewall-for-linux/
# https://gist.github.com/thomasfr/9712418
# https://gist.github.com/SnakeDrak/f4150f6e517e5a1d525f
# http://www.thegeekstuff.com/2011/06/iptables-rules-examples
# http://www.thegeekstuff.com/scripts/iptables-rules
@velizarn
velizarn / nodejs app.launch
Last active December 9, 2016 19:55
Eclipse External Tool Configurations - run selected nodejs file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="D:\programs\nodejs\node.exe"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="${selected_resource_name}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${container_loc}"/>
</launchConfiguration>
@velizarn
velizarn / obtain_token.js
Last active October 16, 2019 14:48
Obtain OAuth token in Nodejs for SalesForce Commerce Cloud OCAPI (previously Demandware)
const https = require('https')
const headers = {
'Authorization' : 'Basic YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhOmFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==',
'Content-Type' : 'application/x-www-form-urlencoded'
}
const optionsget = {
host : 'account.demandware.com',
port : 443,
@velizarn
velizarn / delete_dirs.xml
Last active June 13, 2016 20:36
Ant task to delete non-empty directories
<target name="delete.node_modules">
<echo message="Delete node_modules from build directory"/>
<delete verbose="false" includeemptydirs="true">
<fileset dir="${basedir}/build/node_modules" includes="**/*" defaultexcludes="false" />
</delete>
<delete dir="${basedir}/build/node_modules" />
</target>
@velizarn
velizarn / ecipse.ini
Last active January 9, 2017 13:26
Eclipse INI configuration
-cssTheme
none
-startup
plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
-vm
C:/Program Files/Java/jdk1.8.0_60/bin/javaw.exe
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.300.v20150602-1417
-product
org.eclipse.epp.package.committers.product