Skip to content

Instantly share code, notes, and snippets.

View madan712's full-sized avatar

Madan Chaudhary madan712

View GitHub Profile
@madan712
madan712 / pom.xml
Created June 27, 2019 19:16
Java - Export database tables to an excel file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javaxp</groupId>
<artifactId>TestExport</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>TestExport</name>
<url>http://maven.apache.org</url>
@madan712
madan712 / export_db.py
Last active October 6, 2024 07:54
Python - export mysql table to excel file
import xlsxwriter
import mysql.connector
def fetch_table_data(table_name):
# The connect() constructor creates a connection to the MySQL server and returns a MySQLConnection object.
cnx = mysql.connector.connect(
host='localhost',
database='schema',
user='user',
@madan712
madan712 / test-mysql.py
Last active June 23, 2019 09:35
Python - Connect mysql
import mysql.connector
# The connect() constructor creates a connection to the MySQL server and returns a MySQLConnection object.
cnx = mysql.connector.connect(
host="localhost",
database="schema",
user="root",
password="password"
)
@madan712
madan712 / pom.xml
Last active June 21, 2019 20:45
Empty pom.xml for new maven project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javaxp</groupId>
<artifactId>project-name</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>project-name</name>
<url>http://maven.apache.org</url>
@madan712
madan712 / read_write_file.py
Last active June 17, 2022 10:42
Python - Read and write a text file
def write_file():
print("Writing a file..")
try:
f = open("my_file.txt", "a")
for num in range(100):
f.write("Line " + str(num) + "\n")
f.close()
except Exception:
print("Could not write to file")
@madan712
madan712 / Index.js
Created June 1, 2019 10:36
Index.js - Example with React, Redux and Axios API
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {Provider} from 'react-redux';
import AppStore from "./AppStore";
ReactDOM.render(<Provider store={AppStore}><App/></Provider>, document.getElementById('root'));
serviceWorker.unregister();
@madan712
madan712 / AppStore.js
Created June 1, 2019 10:35
AppStore.js - Example with React, Redux and Axios API
import {createStore, applyMiddleware} from 'redux';
import AppReducer from "./AppReducer";
import thunk from 'redux-thunk';
const AppStore = configureStore();
function configureStore() {
return createStore(AppReducer, applyMiddleware(thunk));
}
@madan712
madan712 / AppReducer.js
Created June 1, 2019 10:34
AppReducer.js - Example with React, Redux and Axios API
const initialState = {
name: '',
response: ''
};
export default function AppReducer(state = initialState, action) {
const newState = Object.assign({}, state);
switch (action.type) {
case 'UPDATE_NAME':
newState.name = action.name;
@madan712
madan712 / AppApi.js
Created June 1, 2019 10:33
AppApi.js - Example with React, Redux and Axios API
import axios from 'axios';
class AppApi {
static sayHello(name) {
return new Promise((resolve, reject) => {
const url = 'http://localhost:8080/sayhello';
axios.get(url, { params: { name: name } }).then(response => {
console.log(response);
resolve(response.data);
}).catch(error => {
@madan712
madan712 / AppAction.js
Created June 1, 2019 10:33
AppAction.js - Example with React, Redux and Axios API
import AppApi from './AppApi';
export function updateName(name) {
return { type: 'UPDATE_NAME', name };
}
function loadResponse(response) {
return { type: 'LOAD_RESPONSE', response };
}