Skip to content

Instantly share code, notes, and snippets.

View clementsjj's full-sized avatar

JJ Clements clementsjj

View GitHub Profile

Using Colorama

pip install colorama
#
from colorama import Fore, Back, Style

# Colors
Fore.RED
Back.GREEN
Style.RESET_ALL
def is_prime(x):
return not any(x//i == x/i for in range(x-1, 1, -1))
SELECT username, email, COUNT(*)
FROM users
GROUP BY username, email
HAVING COUNT(*) > 1
const regexDesc = />(.*?)<\/a>/;
const descriptionContent = $(value)
  .find('description')
  .text();
const description = regexDesc.exec(descriptionContent)[1];
handleValue1031InputChange = event => {
  let value1031 = event.target.value
  if (value1031.length === 0) {
    this.setState({ value1031: '', isValidValue1031: false })
  } else if (value1031.length > 0 && this.validateValue1031(value1031)) {
    value1031 = this.commify(value1031)
    this.setState({ value1031, isValidValue1031: true })
  }
}
@clementsjj
clementsjj / sort-array-of-objects.md
Created September 20, 2019 17:46
Sort an array of objects by date epoch
const forms = [
  {id: 1, text: 'sell', time_created: 1568922447},
  {id: 2, text: 'buy', time_created: 1568929208}
]

const messages = [
  {id: 1, text: 'yo bozo boy', time_created: 1568842057},
  {id: 2, text: 'ill take it', time_created: 1568999255}
]
let tempnames = []
const users = [1217, 9000]
const contacts = [
  {user_id: 1217, name: 'JJ'},
  {user_id: 3000, name: 'Muffin'},
  {user_id: 4500, name: 'Jessie'},
  {user_id: 9000, name: 'Iggy'},
]
focusedOnInput = () => {
if (document.getElementById('MessageInput')) {
setTimeout(() => document.getElementById('MessageInput').focus(), 0)
}
}
  • Bring necessary modules
    const socketIO = require('socket.io')
    const app = require('./backend/app')

  • Wrap socketio with server
    const io = socketIO(httpServer)

  • Assign variables and io to app
    app.userIdToSocket = {}
    app.io = io.on('connection'...

Stringify

value={JSON.stringify(option)} JSON.parse(value)

or

Use Index

value={index} then use in array this.setState({option: this.props.listOption[e.target.value].obj})