Skip to content

Instantly share code, notes, and snippets.

View jvadillo's full-sized avatar
💭
Code, Learn & Teach

Jon jvadillo

💭
Code, Learn & Teach
View GitHub Profile
@jvadillo
jvadillo / routes.js
Last active June 22, 2017 09:53
Express + Node.js + Mongodb: get parametter attribute list and search by $in operator
var express = require('express');
var router = express.Router();
/**
* Get events from the REST webservice
* [GET] url: https://mydomain.com/event/params?eventType=festival,gallery,show
*/
router.get('/event', function(req, res) {
var query = {}; //query for MongoDB
var arr,subq;
@jvadillo
jvadillo / csvToArray.js
Created August 27, 2016 15:27
Javascript: Convert comma separated string to array
var array = string.split(',');
@jvadillo
jvadillo / queryDateRange.js
Created August 27, 2016 15:29
[MongoDB] Querying for a Date Range
items.save({
name: "example",
created_at: ISODate("2010-04-30T00:00:00.000Z")
})
items.find({
created_at: {
$gte: ISODate("2010-04-29T00:00:00.000Z"),
$lt: ISODate("2010-05-01T00:00:00.000Z")
}
})
@jvadillo
jvadillo / serializeForm2JSON.js
Created August 27, 2016 16:32
[HTML & JS] Serialize Form to JSON
function serializeToJSON(form) {
var jsonData = {};
console.log('......serializeToJSON');
var formData = form.serializeArray();
$.each(formData, function() {
if (jsonData[this.name]) {
if (!jsonData[this.name].push) {
jsonData[this.name] = [jsonData[this.name]];
}
<div class="info-row amenities">
<p>
{{substr "140" description}}
</p>
</div>
@jvadillo
jvadillo / appevents.js
Created August 29, 2016 14:38
Dynamic mongodb query generation with Node.js driver
router.get('/search', function(req, res) {
var query = {};
var arr;
var subq;
var styles;
//Styles filter
if (req.query.styles) {
styles = req.query.styles;
@jvadillo
jvadillo / app.js
Created August 29, 2016 14:44
URL Parameters in Express.js
router.get('/:id', function(req, res) {
var eventID = req.params.id;
});
//http://myurl.com/search?param1=value1&param2=value2
router.get('/search', function(req, res) {
var param1,param2;
if (req.query.param1) {
param1 = req.query.param1;
@jvadillo
jvadillo / paragraphStyle.css
Created September 1, 2016 16:45
Show saved text in textarea with breaklines
.wrap {
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */
white-space: -pre-wrap; /* Opera <7 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* IE */
}
@jvadillo
jvadillo / client.js
Created September 2, 2016 12:55
Handlebars.js client side dynamic
var someAsyncFunction = function(callback) {
setTimeout(function() {
var template = '<h1>{{message}}</h1>';
callback(template);
}, 1000);
};
$(document).ready(function() {
someAsyncFunction(function(template) {
var compiledTemplate = Handlebars.compile(template);
@jvadillo
jvadillo / bullets.css
Created May 17, 2017 09:53
CSS: Space between bullet and <li>
li:before {
content: "";
display: inline-block;
height: 1rem; // or px or em or whatever
width: .5rem; // or whatever space you want
}