Skip to content

Instantly share code, notes, and snippets.

BetterProgramming

View GitHub Profile
View draghandler.js
const bind = useDrag(
({ down, tap, movement: [x] }) => {
// Tap handler
if (!down && tap) {
set({ x: toggled ? -RANGE : 0 });
setToggled(!toggled);
return;
}
// Drag handler
if (down) {
View appconnect.js
io.on('connection', socket => {
console.log("New user connected")
socket.username = "Anonymous"
socket.on('change_username', data => {
socket.username = data.username
})
//handle the new message event
socket.on('new_message', data => {
View appjs_connect.js
io.on('connection', socket => {
console.log("New user connected")
socket.username = "Anonymous"
socket.on('change_username', data => {
socket.username = data.username
})
//handle the new message event
socket.on('new_message', data => {
View chatroom_2.js
let message = document.querySelector('#message')
let messageBtn = document.querySelector('#messageBtn')
let messageList = document.querySelector('#message-list')
messageBtn.addEventListener('click', e => {
console.log(message.value)
socket.emit('new_message', {message: message.value})
message.value = ''
})
socket.on('receive_message', data => {
console.log(data)
View chatroom.js
(function connect(){
let socket = io.connect('http://localhost:3000')
let username = document.querySelector('#username')
let usernameBtn = document.querySelector('#usernameBtn')
let curUsername = document.querySelector('.card-header')
usernameBtn.addEventListener('click', e => {
console.log(username.value)
socket.emit('change_username', {username: username.value})
curUsername.textContent = username.value
View index.ejs
<!DOCTYPE html>
<head>
<title>Simple realtime chatroom</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="title">
<h3>Realtime Chat Room</h3>
</div>
View app.js
const express = require('express')
const socketio = require('socket.io')
const app = express()
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.get('/', (req, res)=> {
res.render('index')
})
const server = app.listen(process.env.PORT || 3000, () => {
console.log("server is running")
View quicksort.js
function quickSort(originalArray) {
if (originalArray.length <= 1) {
return originalArray;
}
else
{
let leftSide = [];
let rightSide = [];
let newArray = [];
let pivot = originalArray.pop();
View modposture.py
def build_message(self):
current_message = ""
if not self.check_head_drop():
current_message += "Lift up your head!\n"
if not self.check_lean_forward():
current_message += "Lean back!\n"
if not self.check_slump():
current_message += "Sit up in your chair, you're slumping!\n"
self.message = current_message
return current_message
View eareye.py
def check_head_drop(self):
if self.key_points['Left Eye'].y != -1 and self.key_points['Left Ear'].y != -1 \
and self.key_points['Left Eye'].y > (self.key_points['Left Ear'].y + (self.scale * 15)):
return False
if self.key_points['Right Eye'].y != -1 and self.key_points['Right Ear'].y != -1 \
and self.key_points['Right Eye'].y > (self.key_points['Right Ear'].y + (self.scale * 15)) :
return False
return True
You can’t perform that action at this time.