Skip to content

Instantly share code, notes, and snippets.

View saswata-dutta's full-sized avatar
💭
I may be slow to respond.

Saswata Dutta saswata-dutta

💭
I may be slow to respond.
View GitHub Profile
@saswata-dutta
saswata-dutta / Maybe.cpp
Created May 24, 2020 20:16 — forked from TheSeamau5/Maybe.cpp
Maybe in C++
#include <string>
#include <functional>
using namespace std;
template <typename T>
struct Maybe{
T just;
bool isNothing;
};
@saswata-dutta
saswata-dutta / postgres_db_read.py
Created May 22, 2020 05:04
read data from postgres
import psycopg2
from datetime import datetime
def printline(r):
correspondence_id, account_id, case_id, created_date, internal_external_flag, to_line, from_line, cc_line = r
print(f"{correspondence_id},{account_id},{case_id or ''},{created_date.isoformat()},{internal_external_flag},{to_line},{from_line},{cc_line or ''}")
######
user = 'username'
static void clear(String source) {
try {
Field charField = String.class.getDeclaredField("value");
charField.setAccessible(true);
SecureRandom random = SecureRandom.getInstanceStrong();
char[] noise = new char[source.length()];
for (int i = 0; i < source.length(); i++) {
noise[i] = (char) random.nextInt(Character.MAX_VALUE + 1);
}
//////
// https://www.postgresqltutorial.com/postgresql-jdbc/transaction/
/////
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
package com.labex;
import java.sql.*;
public class JDBCTest {
// JDBC driver name
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
//database url
static final String DB_URL = "jdbc:mysql://localhost/example";
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT id, name, age FROM students";
ResultSet rs = stmt.executeQuery(sql);
// update data in Result Set
rs.moveToInsertRow();
rs.updateInt("id",5);
public class test {
public static void main(String[] args) {
// get date and time
// here we use java.util.Date class for comparison with java.sql.Date
java.util.Date javaDate = new java.util.Date();
long javaTime = javaDate.getTime();
System.out.println("The Java Date is:" +
javaDate.toString());
// get SQL date in java.sql.Date format
function loadJquery() {
var jq = document.createElement('script');
jq.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
};
function moveSim(id) {
payload = {
???
/////////////
// use transactions
try
{
// close auto commit
conn.setAutoCommit(false);
//1 or more queries or updates
@saswata-dutta
saswata-dutta / jdbc_snippet.java
Created April 12, 2020 08:41
auto close jdbc resources
public List<User> getUser(int userId) {
try (Connection con = DriverManager.getConnection(myConnectionURL);
PreparedStatement ps = createPreparedStatement(con, userId);
ResultSet rs = ps.executeQuery()) {
// process the resultset here, all resources will be cleaned up
} catch (SQLException e) {
e.printStackTrace();
}