Snippets Collections
from faker import Faker
from SmileyDB3 import SmileyDB3
from random import randint

import webbrowser

f = Faker()
db = SmileyDB3('mydb.db')

users = db.table('users')

for i in range(20):
    users.Insert(data={
        'name': f.name(),
        'email': f.email(),
        'age': randint(20, 40)
    })

users.convert().to_html('out.html')

webbrowser.open('out.html')
import sqlite3

db = sqlite3.connect('mydb.db')
cur = db.cursor()

# create users table
cur.execute('CREATE TABLE IF NOT EXISTS users (name str, image blob)')

# insert new user in users table
cur.execute(
    'INSERT INTO users (name, image) VALUES (?, ?)', 
    ('USER-123', open('smile.png', 'rb').read())
)

db.commit()
from faker import Faker
from random import randint

f = Faker()

data = {'name': 'Barry Long', 'email': 'tammy28@example.com', 'age': 20}

# Generate data from this 
def Generate_like_this(data : dict, f : Faker):
    result = {}

    funcs = {
        'name': f.name,
        'email': f.email
    }

    for k in data:

        if k in funcs:
            result[k] = funcs[k]()

        if isinstance(data[k], int):
            result[k] = randint(1, data[k])
        
    
    return result

print(Generate_like_this(data = data, f = Faker()))
import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Define the data to be inserted as a list of tuples
data = [
    ('John Doe', 'johndoe@example.com'),
    ('Jane Smith', 'janesmith@example.com'),
    ('Mike Johnson', 'mikejohnson@example.com')
]

# Use executemany() to insert the data into the "users" table
cursor.executemany("INSERT INTO users (name, email) VALUES (?, ?)", data)

# Commit the changes
con.commit()
import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Update user name based on ID
user_id = 2
new_name = "John Doe"

cursor.execute("UPDATE users SET name = ? WHERE id = ?", (new_name, user_id))

# Commit the changes
con.commit()
import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Fetch all data from the "users" table
cursor.execute("SELECT * FROM users")
data = cursor.fetchall()

# Print the retrieved data
for row in data:
    print(row)
import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Delete user based on ID
user_id = 123

cursor.execute("DELETE FROM users WHERE id = ?", (user_id,))

# Commit the changes
con.commit()
import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Fetch data based on the ID filter
cursor.execute("SELECT * FROM users WHERE id = ?", (123,))
data = cursor.fetchall()

# Print the retrieved data
for row in data:
    print(row)

import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Create a cursor object
cursor = con.cursor()

# Insert a new user
cursor.execute("INSERT INTO users (name, email) VALUES (?, ?)", ("John Doe", "johndoe@example.com"))

# Commit the changes
con.commit()

from peewee import Model, SqliteDatabase, CharField, IntegerField, UUIDField
from uuid import uuid4
from faker import Faker
from random import randint

fake = Faker()

db = SqliteDatabase('mydb.db')

class User(Model):
    name = CharField(max_length = 25)
    email = CharField(max_length = 25)
    age = IntegerField()
    password = CharField(max_length = 100)
    user_id = UUIDField(primary_key = True, default = uuid4)

    class Meta:
        database = db


db.connect()
db.create_tables([User])

for i in range(20):
    new_user = User.create(**{
        'name': fake.name(),
        'email': fake.email(),
        'age': randint(12, 45),
        'password': fake.password()
    })

    new_user.save()

db.commit()
from peewee import SqliteDatabase, Model, UUIDField, CharField, IntegerField
from uuid import uuid4

db = SqliteDatabase('mydb.db')

# Create user Model
class User(Model):
    userId = UUIDField(primary_key = True, default = uuid4)
    name = CharField(max_length = 10)
    age = IntegerField()

    class Meta:
        database = db

# Connect to db
db.connect()
db.create_tables([User])
db.commit()

# Add new user to database
user = User.create(name = 'user123', age = 20)
user.save()

# Get all users
for user in User.select():
    print(user.name, user.userId)
import { jsPDF } from "jspdf";

export default async function lead({
}) {

  const doc = new jsPDF('p', 'pt', 'a4');
  doc.setFontSize(12)
  doc.html(document.getElementById("dream-house-full"),  {
    useCORS: true,
    autoPaging:'text',
    // html2canvas:
    callback: function (pdf) {
      pdf.save("12.pdf");
    },
    html2canvas: {
      scale: 0.5,
      // ignoreElements: element => element.id === autoTableConfig?.elementId,
    },
    x:10,
    y:10,
    width:1400,
  });
  // doc.save("a4.pdf");

  // htmlPdf.create(html, options).then((pdf) => pdf.toFile('test.png'));
}
SELECT EXISTS (
   SELECT FROM information_schema.tables 
   WHERE  table_schema = 'public'
   AND    table_name   = 'abcd'
   );
#!/usr/bin/python



-- coding: UTF-8 --


pip install MySQL-python



import MySQLdb, os




try:
    conn = MySQLdb.connect(host='172.17.42.1', user='my_email', passwd='normal', db='database', port=3306)




cur = conn.cursor()
cur.execute('SELECT `id`, `name`, `path`, FROM `doc_file`')

# results
resulsts=cur.fetchall()    id, name, path = r[0], r[1], r[2]

    if path and not os.path.exists(path):
        print 'file not exist: ', id, name, path, flashpath

cur.close()
conn.close()

 



except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])




</pre> 

 

 



                    
 
 """ 
'UserWarning: pyproj unable to set database path.' <- This happens with multiple pyproj installations on the same machine, which is quite common, as almost every geo software depends on it.

How to fix:
First, find all copies of 'proj.db' on the machine. Get the path for the correct one, which is probably something like 'C:/Users/Clemens Berteld/.conda/pkgs/proj-8.2.0-h1cfcee9_0/Library/share/proj'. Definitively not a QGIS or PostGIS path.

Then, use it as a parameter for this function and run it at the top of your code:
"""

def set_pyproj_path(proj_path):
    from pyproj import datadir
    datadir.set_data_dir(proj_path)
    # print(datadir.get_data_dir.__doc__)
Inbox
id, userId(holder of this account), senderId, lastMessage

Chat
id, senderId, recieverId, message, seen, deleted

//
DB query when inbox is opened
findall where userId = senderId or userid = receiverId
SELECT count(*) as application, YEARWEEK(created_date) as weekNum
FROM nepaldevjobsapplication
GROUP BY YEARWEEK(created_date)
$this->load->library("form_validation");
$this->form_validation->set_rules("username", "User name", "trim|required");
if($this->form_validation->run() === FALSE)
{
     //$this->view_data["errors"] = validation_errors();
}
else
{
     //codes to run on success validation here
}
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick')); // insert in ci
# If your logged in to mysql (mysql -u root -p) you can create the database
#CREATE DATABASE database_name;
CREATE DATABASE <database> CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';

# The user can be created with
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';

# This user also needs access to the database
GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';

# To make the new access rights available you have to reload them
FLUSH PRIVILEGES;

WPDBNAME=`cat wp-config.php | grep DB_NAME | cut -d \' -f 4`
WPDBUSER=`cat wp-config.php | grep DB_USER | cut -d \' -f 4`
WPDBPASS=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
Db::getInstance()->executeS("DELETE FROM product_images WHERE id_product NOT IN (" . join($allProductIds,',') . ")")
star

Sat Jan 20 2024 02:11:01 GMT+0000 (Coordinated Universal Time) https://github.com/LaravelDaily/laravel-tips/blob/master/db-models-and-eloquent.md

#laravel #database #eloquent #model
star

Tue Aug 01 2023 16:01:12 GMT+0000 (Coordinated Universal Time)

#database #postgresql #nodejs #indiafirst #javascript #pgadmin4
star

Fri Mar 03 2023 02:59:12 GMT+0000 (Coordinated Universal Time) https://www.open-open.com/code/view/1457829300325

#python #mysql #database #thirdparty
star

Thu Aug 18 2022 07:19:21 GMT+0000 (Coordinated Universal Time)

#pyproj #python #database #path
star

Sun Mar 06 2022 15:55:10 GMT+0000 (Coordinated Universal Time)

#database
star

Sat Mar 05 2022 19:27:18 GMT+0000 (Coordinated Universal Time)

#database
star

Thu Feb 24 2022 13:43:32 GMT+0000 (Coordinated Universal Time)

#php #codeigniter #database #model
star

Thu Feb 24 2022 09:08:59 GMT+0000 (Coordinated Universal Time)

#php #codeigniter #database #model
star

Thu Feb 24 2022 08:48:16 GMT+0000 (Coordinated Universal Time) https://codeigniter.com/userguide3/database/query_builder.html

#php #codeigniter #database #model
star

Fri Jun 11 2021 14:23:59 GMT+0000 (Coordinated Universal Time)

#database #mysql
star

Mon Jun 07 2021 18:06:54 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/7586995/read-variables-from-wp-config-php

#wordpress #database #credentials #automate
star

Tue Mar 02 2021 10:31:38 GMT+0000 (Coordinated Universal Time)

#prestashop #delete #mysql #db #database #ids
star

Thu Aug 06 2020 13:55:46 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/a/39816161/6942743

#sql #database #querying-data

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension