Skip to content

Instantly share code, notes, and snippets.

View nadeemelahi's full-sized avatar

Nadeem nadeemelahi

View GitHub Profile
@nadeemelahi
nadeemelahi / gist:10367539
Last active August 29, 2015 13:58
count down timer
<p id="whiteTimeLeft"></p>
<button id="start">start</button>
<button id="stop">stop</button>
var secs = 599;
function decrementTimer() {
var currentMinutes = "0" + Math.floor(secs / 60);
var currentSeconds = Math.floor((secs % 60));
if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds;
var timeLeft = currentMinutes + ":" + currentSeconds;
if you have button with a click handler, and you remove it from dom, does the handler remain?
if you call removeChild on its parent, then the handler is gone. if you instead append it to a document fragment, it will keep it
jQuery .revome() kills the handler. jquery "detach" will keep it
var https = require('https')
var httpSSLserver = https.createServer()
httpSSLserver.listen(443);
var http = require('http')
var httpServer = http.createServer()
var io = require('socket.io').listen(httpServer);
httpServer.listen(80);
@nadeemelahi
nadeemelahi / gist:922fc3dc62405a59d341
Created May 12, 2014 23:27
socket.io peerjs clients list
var io = require('socket.io').listen(httpServer);
httpServer.listen(8080);
io.set('log level', 1);
var peerWebRTC = io.of('/peerWebRTC');
var PeerServer = require('peer').PeerServer;
var idIncr = 0;
var clientpeerIds = [];
var clientData = {}; /* by clientpeerIds */
SERVER
var fs = require('fs'),
url = require('url'),
http = require('http'),
path = require('path');
var PORT = 8000,
SAVE_PATH = './receivedCaps';
http.createServer(function(req, res) {
var nano = require('nano');
var couchdb = nano('http://127.0.0.1:5984');
var redis = require('redis');
var http = require('http');
var connect = require('connect');
var RedisStore1 = require('connect-redis')(connect);
var io = require('socket.io');
var cookie = require('cookie');
var sessionStore = new RedisStore1();
//THIS WORKS FINE
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var static = require('node-static');
// Make all the files in the current directory accessible
var fileServer = new static.Server('./public');
app.listen(8000);
I copied this example http://chessboardjs.com/examples#5000 which integrates https://github.com/jhlywa/chess.js
Then I tweaked this script: <script src="js/chessboard.js"></script>
I changed the addEvents function to only register mouse event handler for desktops because when I tested it on old android browsers, touchstart and mousedown events were both firing:
if (isTouchDevice() === true) {
boardEl.on('touchstart', '.' + CSS.square, touchstartSquare);
containerEl.on('touchstart', '.' + CSS.sparePieces + ' .' + CSS.piece,
touchstartSparePiece);
//$(window).on('touchmove', touchmoveWindow); nad cutout
//$(window).on('touchend', touchendWindow); nad cutout
} else { // all the same mouse stuff that is in the default setup
public class Main {
public static void main(String[] args) {
String inputString = "test input string for first non repeating char z";
String uniqueCharInInputStringString;
int len = inputString.length();
char testChar;
boolean foundDuplicate;