Skip to content

Instantly share code, notes, and snippets.

@heylastway
heylastway / convert.sql
Last active October 31, 2019 14:55
How to convert all Database Tables and Columns to a specific Collation.
# 1.Convert the Collation of a Database
ALTER DATABASE DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci;
# 2.Convert the Collation of all Tables
SELECT CONCAT("ALTER TABLE ", TABLE_SCHEMA, '.', TABLE_NAME,' COLLATE utf8_general_ci;')
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DBNAME' AND TABLE_TYPE = 'BASE TABLE';
# 3.Convert the Collation of Table Columns
SELECT CONCAT('ALTER TABLE `', TABLE_NAME,'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') AS mySQL
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= "DBNAME" AND TABLE_TYPE="BASE TABLE"
@heylastway
heylastway / Audio preloader.js
Last active October 31, 2019 14:53
How to preload a sound in Javascript.
// Audio preloader
$(window).ready(function(){
var audio_preload = 0;
function launchApp(launch){
audio_preload++;
if ( audio_preload == 3 || launch == 1) { // set 3 to # of your files
start(); // set this function to your start function
}
}
//Infinite scroll
$(document).ready(function(){
$('#Loader').on('inview', function(event, isInView) {
if (isInView) {
var nextPage = parseInt($('#pageno').val())+1;
//Filters
const Discord = require("discord.js");
const fs = require('fs');
module.exports = class mute {
constructor(){
this.name = 'mute',
this.alias = ['tempmute'],
this.usage = 'mute';
}
INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12)
ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2);
ALTER TABLE tablename AUTO_INCREMENT = 1
SELECT order_id,product_name,qty
FROM orders
WHERE foo = 'bar'
INTO OUTFILE '/var/lib/mysql-files/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
#!/usr/bin/python
import MySQLdb
# Connect
db = MySQLdb.connect(host="localhost",
user="appuser",
passwd="",
db="onco")
cursor = db.cursor()
SELECT id, MAX(rev)
FROM YourTable
GROUP BY id
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";