Skip to content

Instantly share code, notes, and snippets.

View datacorner's full-sized avatar

datacorner datacorner

View GitHub Profile
@datacorner
datacorner / gist:e8d533c577e62e712f453a355e671ee8
Created March 9, 2019 15:01
Python Timer JSON API call each x seconds ...
from threading import Timer
import requests
import pandas as pd
from time import localtime, strftime
def update():
getData()
set_timer()
def set_timer():
@datacorner
datacorner / gist:47f99b6674fbe033a0f82e0405a94dc3
Last active September 20, 2018 06:51
This function scrap one html page by gathering the XPath data (using the tags array) and give back a Pandas DataFrame
import requests
import lxml.html as lh
import pandas as pd
# URL
url = '...'
# XPath content to collect
tags = ['//a[@class="XX"]', \
'//p[@class="XX"]' , \
@datacorner
datacorner / putfiletostring.java
Created May 17, 2018 12:34
Read a file and put it into a String variable
/**
* Read a file and put it into a String variable
* @param filename
* @return
*/
public static String FILE_TO_STRING(String filename) {
BufferedReader reader = null;
try {
InputStream myFile = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
reader = new BufferedReader(new InputStreamReader(myFile));
@datacorner
datacorner / callcommandline.java
Created May 17, 2018 12:32
Execute a commande line in synchronous call mode
/**
* Execute a commande line in synchronous call mode
* @param line command line
* @return result
*/
public String EXECUTE_CMD(String line) {
String retValue = "";
try {
if (!line.equalsIgnoreCase("")) {
Process p = Runtime.getRuntime().exec(line);
@datacorner
datacorner / webinf_realpath.java
Created May 17, 2018 12:30
Returns the real system path of WEB-INF
/**
* Returns the real system path of WEB-INF through a servlet
* @return répertoire WEB-INF
*/
public static String WEBINF_PATH() {
String className = JoyConfigfileProvider.class.getName().replaceAll("\\.", "/") + ".class";
// Use the ClassLoader to find the absolute path to this file.
URL classPath = JoyConfigfileProvider.class.getClassLoader().getResource(className);
//create a new File and go from file to parent file to find the WEB-INF directory
File f = new File(classPath.getPath());
@datacorner
datacorner / drawhist1string.py
Last active May 17, 2018 08:21
Draw 1 histogram with string labels in Python matplotlib
# Where matplotlib do not work (when using string labels for hist())
from collections import Counter
def hist_string(df) :
distincts_count = Counter(df)
df = pd.DataFrame.from_dict(distincts_count, orient='index')
df.plot(kind='bar')
hist_string(titanic.Embarked)
@datacorner
datacorner / drawhist2string.py
Last active May 17, 2018 08:46
Draw 2 histograms with string labels in Python matplotlib
# The goal here is to create a double histogram with string labels which is not supported yet with the hist() matplotlib function
import matplotlib.pyplot as plt
import numpy as np
from collections import Counter
# Dead list
l1 = titanic[titanic["Survived"] == 0]["Embarked"].dropna()
# Survivor list
l2 = titanic[titanic["Survived"] == 1]["Embarked"].dropna()