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 / 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 / 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 / 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 / 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
}
@jvadillo
jvadillo / ES6useful.js
Created June 17, 2017 08:45
Javascript ES6 useful functions
/**
* Filter object array (e.g. filter those with id>100):
*/
//In ES6:
objectList.filter(obj => obj.id > 100);
//In ES5:
objectList.filter(function (obj) {
return obj.id > 18;
});
@jvadillo
jvadillo / react-conditional-rendering.js
Created June 17, 2017 09:27
Conditional rendering in React
class ConditionalComponent extends React.Component {
render() {
const isLoggedIn = true;
let button = null;
if (isLoggedIn) {
button = <LogoutButton />;
} else {
button = <LoginButton />;