Skip to content

Instantly share code, notes, and snippets.

<new_textarea_field name="message" label="Message: ">
<validation>
<min length="10">Please, enter at least 10 characters.</min>
</validation>
</new_textarea_field>
<new_textarea_field name="message" label="Message: ">
<validation>
<max length="10">Please, enter at most 10 characters.</max>
</validation>
</new_textarea_field>
<new_text_field name="telephone" label="Phone: ">
<validation>
<regex pattern="^[0-9]+$">Please, enter only numbers.</regex>
</validation>
</new_text_field>
<new_file_field name="photo" label="Photo: ">
<validation>
<extension valid="jpeg, png">Select a jpeg or png photo</extension>
<mime valid="image/jpeg, image/png">Select a jpeg or png photo</mime>
</validation>
</new_file_field>
<!-- EMAIL CONFIG -->
<email_settings>
<recipients to="point_to_field:subject" cc="" bcc="" />
<smtp auth="yes" host="" username="" password="" secure_type="tls" port="587" />
<subject>Someone is getting in touch with you!</subject>
</email_settings>
<!-- FIELDS SETTINGS -->
<fields>
<new_radio_list name="subject" label="Subject: ">
@lucaswxp
lucaswxp / gist:766faddb92dd219d7ca0
Created February 12, 2015 17:56
Disable bodyparser in sails 0.9.x

In config/local.js just set bodyParser to return a placeholder function:

module.exports.express.bodyParser = function(){
  return function(req, res, next){ next(); }
}

Setting the property to false won't work because of a bug, so that's the best we got.

@lucaswxp
lucaswxp / socket.io force new connection not working fix.md
Last active August 29, 2015 14:16
socket.io force new connection not working fix

Socket.io connected the first time, but after disconnected, I couldn't connect again manually.

For me, the flags 'force new connection' and 'forceNew' wasn't working properly like some places says it should, and I couldn't find any way around it. Using socket.io 1.3.5, this is what I did to fix it:

var once = false;

function getSocket(){
 var socket = io({path: '/socket.io'}, {'force new connection':true});
@lucaswxp
lucaswxp / Check field exists in model django snippet.md
Last active June 30, 2024 03:00
Check field exists in model django snippet

In your models.py put:

from django.db import models

@classmethod
def model_field_exists(cls, field):
    try:
        cls._meta.get_field(field)
 return True
@lucaswxp
lucaswxp / CakePHP script for generating pot translations files.md
Last active August 29, 2015 14:19
CakePHP script for generating pot translations files

This script executes cake i18n extract with all the defaults args and returns the command output.

function extractPotFiles(){
  $app = ROOT . DS . APP_DIR;
  $cake = $app . DS . 'Console' . DS . 'cake';
  $olddir = getcwd();
  chdir($app);

  $descriptorspec = array(
 0 =&gt; array("pipe", "r"), // stdin is a pipe that the child will read from
@lucaswxp
lucaswxp / read all cookies as array javascript.js
Created June 8, 2015 12:04
read all cookies as object/array javascript
function readCookies() {
var cookies = document.cookie.split(';'),
r = {};
for(var i=0;i < cookies.length; i++) {
var c = cookies[i],
sep = c.indexOf('=');
r[c.substr(1, sep-1)] = c.substr(sep+1);
}
return r;