Skip to content

Instantly share code, notes, and snippets.

@fomvasss
Last active September 3, 2019 06:26
Show Gist options
  • Save fomvasss/5adfa53c404046867aeb27870d48cc17 to your computer and use it in GitHub Desktop.
Save fomvasss/5adfa53c404046867aeb27870d48cc17 to your computer and use it in GitHub Desktop.
JS

Java Script, JQ

   function urlify(text) {
        var regexp = /(https?:\/\/[^\s\"]+)/g;
        res = text.match(regexp);
        return res ? res[0] : '';
        return text.replace(urlRegex, function(url) {
            console.log(url);
            return url;
        })
        // or alternatively
        // return text.replace(urlRegex, '<a href="$1">$1</a>')
    }

Preloader

https://codepen.io/zerospree/pen/aCjAz

<body>
<div class="loader" style="display: none;">
    <div class="loader__wrapper">
        <div class="load">
            <hr/><hr/><hr/><hr/>
        </div>
    </div>
</div>
<script>
    var $loader = $('.loader')
        //$loader.hide()
    $(document)
        .ajaxStart(function () {
            $loader.show()
        })
        .ajaxStop(function () {
            setTimeout(function () {
                $loader.hide()
            }, 100)
        });
    // $.ajaxSetup({
    //     beforeSend: function (xhr) {
    //         $loader.show()
    //     },
    //     complete: function (xhr) {
    //         setTimeout(function () {
    //             $loader.hide()
    //         }, 100)
    //     }
    // })
</script>

NodeJS Casino server:

const PORT = 5000;
var io = require('socket.io')(PORT),
    redis = require('redis');

io.on('connection', function (socket) {

    var redisClient = redis.createClient();
    console.log('User connect!');

    redisClient.subscribe('redis_channel1');

    redisClient.on('message', function(channel, data) {
        data = JSON.parse(data);

        socket.emit('events', data);

    });

    socket.on('disconnect', function () {
        redisClient.quit();
        console.log('User disconnect');
    })

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment