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 / graphql-express-hello-world.js
Created July 12, 2017 11:49
GraphQL Express Hello World Example
var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');
var schema = buildSchema(`
type Query {
hello: String
}
`);
@jvadillo
jvadillo / graphql-hello-world.js
Created July 12, 2017 11:48
GraphQL Hello World example
var { graphql, buildSchema } = require('graphql');
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
type Query {
hello: String
}
`);
// The root provides a resolver function for each API endpoint
@jvadillo
jvadillo / nodejs-hello-world.js
Created July 5, 2017 09:18
Node.js Hello World example
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);
@jvadillo
jvadillo / express-hello-world.js
Last active July 13, 2017 10:16
Express Hello World
const express = require('express') //use the express module
const app = express() //create the express application object
app.get('/', function (req, res) { //create the callback function for handling GET request con '
res.send('Hello World!') //send the response
})
//start listening on port 3000
app.listen(3000, function () {
@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 />;
@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 / 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 / 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 / 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 / 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;