Skip to content

Instantly share code, notes, and snippets.

View xtrinch's full-sized avatar
🐱

Mojca Rojko xtrinch

🐱
View GitHub Profile
var validate = require('sails-hook-validation-ev/lib/validate')
module.exports = {
create: async function(req, res) {
validate(req, (req) => {
req.check('title')
.exists()
.isLength({ min: 1 }).withMessage('must be at least 5 chars long');
req.check('description').exists();
})
var validate = require('sails-hook-validation-ev/lib/validate')
module.exports = {
create: async function(req, res) {
validate(req)
const errors = await req.getValidationResult();
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
return res.ok()
{
"errors": [
{
"location": "params",
"param": "title",
"msg": "Invalid value"
},
{
"location": "params",
"param": "title",
module.exports = {
attributes: {
title: {
type: 'string',
required: true
},
description: {
type: 'string',
required: true
@xtrinch
xtrinch / mock-binary-websocket.py
Last active November 25, 2017 01:16
Simple websocket binary data send simulation
#!/usr/bin/env python
import time
import socket
HOST = 'localhost'
PORT = 9876
ADDR = (HOST, PORT)
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(ADDR)
@xtrinch
xtrinch / addremovechildviewcontroller.swift
Created August 3, 2016 12:56
Add and remove childviewcontroller in swift
// in parent view controller
@IBAction func showChildViewController(sender: AnyObject) {
let testController = self.storyboard!.instantiateViewControllerWithIdentifier("Test") as! Test
self.addChildViewController(testController)
self.view.addSubview(testController.view)
testController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
testController.didMoveToParentViewController(self)
}
// in child view controller