Skip to content

Instantly share code, notes, and snippets.

View adamhalasz's full-sized avatar

Adam Halasz adamhalasz

View GitHub Profile
@adamhalasz
adamhalasz / index.js
Last active August 29, 2015 14:14
Using socket.io with diet.js
// Diet Server
var server = require('diet')
var app = server()
app.listen(8000)
// Socket.io
var io = require('socket.io')(app.server) // <-- use app.server
// Listen on websocket connection
io.on('connection', function(socket){
@adamhalasz
adamhalasz / index.js
Created January 27, 2015 23:09
requirebin sketch
// Diet with Socket.io example
// Diet Server
var server = require('diet')
var app = server()
app.listen(8000)
// Socket.io
var io = require('socket.io')(app.server) // <-- use app.server
@adamhalasz
adamhalasz / new server
Created November 16, 2014 08:10
new server
var server = require('diet')
var app = new server()
app.listen('http://localhost:8000/')
app.get('/', function($){
$.end('hello world')
})
@adamhalasz
adamhalasz / subdomain.js
Last active August 29, 2015 14:00
diet subdomain
subdomain = app.subdomain(app, {
domain : 'subdomain.example.com',
path : __dirname,
public : __dirname+'/resources',
mysql : {
host : 'YOUR_HOST', // usually localhost
user : 'YOUR_USERNAME', // usually root
password : 'YOUR_PASSWORD', // your mysql password
database : 'YOUR_DATABASE_NAME', // your mysql database
},
@adamhalasz
adamhalasz / index.js
Last active August 29, 2015 14:00
response.html() node
// Listen on http://example.com/ and respond with index.html
app.get('/', function(request, response, mysql){
response.html('/index.html', { title: 'Diet.js Example!' });
mysql.end();
});
@adamhalasz
adamhalasz / index.html
Last active August 29, 2015 14:00
response.html() html
<!doctype html>
<html>
<head>
<title>{{-@title}}</title>
</head>
<body>
<h1>Hello World in {{-@title}}</h1>
</body>
</html>
@adamhalasz
adamhalasz / gist:9020056
Last active August 29, 2015 13:56
Hello world in Diet v0.3.x
// Call Diet
var Application = require('diet');
// Initalize Application
app = new Application.setup({
'domain' : 'example.com', // default is localhost (127.0.0.1)
'port' : 80, // default is 80
'path' : __dirname, // required path to this folder __dirname is ok
'public' : __dirname +'/resources', // required path to the app resources (images etc..)
'header' : init, // function that runs when the server loaded completly (mysql etc...)
@adamhalasz
adamhalasz / Node.js
Last active December 11, 2015 13:58
// this is javascript
ajax('http://node.yoursite.com/push', node_options)
ajax('http://php.yoursite.com/mysql_query', php_options)
@adamhalasz
adamhalasz / Node.js
Last active December 11, 2015 13:58
app.get('/query', function(request, response){
// Query your database
db.query('SELECT * FROM users', function(rows){
// Push notification to dan
socket.emit('database_query_executed', 'to_dan', rows);
// End request
response.end('success');
});
// Setup
var http = require('http'); // require http module
var port = 80; // http port
var host = '127.0.0.1' // localhost
// This function will be called when a request arrives from a client
function onRequest(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'}); // headers
response.end('Hello World'); // end response
}