Skip to content

Instantly share code, notes, and snippets.

View ilhomelv's full-sized avatar

Hooja ilhomelv

  • Los Angeles, CA
View GitHub Profile
@ilhomelv
ilhomelv / chat.html
Created February 23, 2018 17:06 — forked from dskanth/chat.html
Client file for Private chat using node.js and socket.io
<script src="/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
var my_username = '';
function send_individual_msg(id)
{
//alert(id);
//alert(my_username);
socket.emit('check_user', my_username, id);
//socket.emit('msg_user', id, my_username, prompt("Type your message:"));
@ilhomelv
ilhomelv / app.js
Created February 23, 2018 17:02 — forked from dskanth/app.js
Server file for Private chat using node.js and socket.io
var app = require('express').createServer()
var io = require('socket.io').listen(app);
var fs = require('fs');
app.listen(8008);
// routing
app.get('/', function (req, res) {
res.sendfile(__dirname + '/chat.html');
});
@ilhomelv
ilhomelv / loadJson.js
Created January 25, 2018 13:36 — forked from pwittchen/loadJson.js
Loading JSON file with JavaScript. Please note: it won't run as a "local" script. JavaScript does not allow to load local files due to security reasons. You should deploy it on the server in order to load JSON file.
function loadJson(callback) {
var XmlHttpRequest = new XMLHttpRequest();
XmlHttpRequest.overrideMimeType("application/json");
XmlHttpRequest.open('GET', 'file.json', true);
XmlHttpRequest.onreadystatechange = function () {
if (XmlHttpRequest.readyState == 4 && XmlHttpRequest.status == "200") {
// .open will NOT return a value
// but simply returns undefined in async mode so use a callback
callback(XmlHttpRequest.responseText);
}
@ilhomelv
ilhomelv / save.php
Created January 24, 2018 21:36 — forked from techslides/save.php
Save Ajax POST data as a file with PHP
<?php
//error_reporting(E_ALL);
//var_dump($_SERVER);
$post_data = $_POST['data'];
if (!empty($post_data)) {
$dir = 'YOUR-SERVER-DIRECTORY/files';
$file = uniqid().getmypid();
$filename = $dir.$file.'.txt';
$handle = fopen($filename, "w");
fwrite($handle, $post_data);
@ilhomelv
ilhomelv / index.html
Created January 24, 2018 21:35 — forked from techslides/index.html
HTML Ajax POST call to PHP
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Save Data with Ajax and PHP</title>
</head>
<body>
<textarea id="data">Enter some content here you want to save as a file</textarea>
<button id="save" onclick="save();return false;">Save</button>
<div id="response"></div>