Skip to content

Instantly share code, notes, and snippets.

View singh1114's full-sized avatar

Ranvir Singh singh1114

View GitHub Profile
@singh1114
singh1114 / routes.js
Last active May 10, 2020 20:54
schema for route parameter validation middleware.
router.post('/abc', validateParams([
{
param_key: 'abc',
required: true,
type: 'string',
validator_functions: [(param) => {return param.length === 10}]
}]), routeFunction);
@singh1114
singh1114 / param_middleware.js
Last active January 25, 2021 20:11
Node.js middleware article
const validateParams = function (requestParams) {
return function (req, res, next) {
for (let param of requestParams) {
if (checkParamPresent(Object.keys(req.body), param)) {
let reqParam = req.body[param.param_key];
if (!checkParamType(reqParam, param)) {
return res.send(400, {
status: 400,
result: `${param.param_key} is of type ` +
`${typeof reqParam} but should be ${param.type}`
@singh1114
singh1114 / background.py
Last active August 22, 2017 20:24
Python script to allow put background into the HTML created using `pandoc`
import sys
# Read the second command line argument as the file name
read_file = open(sys.argv[1], 'r')
# Read the third command line argument as the output file name
write_file = open(sys.argv[2], 'w')
temp = ''
flag = 0
{
'scan_result':OrderedDict( [
('scanned_json_result',
{
u'files':[
{
u'licenses':[
{
u'category':u'Permissive',
u'dejacode_url': u'https: //enterprise.dejacode.com/urn/urn: dje: license:apache-2.0',
from django.test import TestCase
from scanapp.models import ScanInfo
class ScanInfoTestCase(TestCase):
def test_scan_info_added(self):
URL_scan_info = ScanInfo(scan_type="URL", is_complete=True)
local_scan_info = ScanInfo(scan_type="localscan", is_complete=False)
URL_scan_info = ScanInfo.objects.get(scan_type="URL")