Skip to content

Instantly share code, notes, and snippets.

<?php
function pluralize( $count, $text )
{
return $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}s" ) );
}
function finddiff($datetime1, $datetime2)
{
$final_result = [];
@sany2k8
sany2k8 / FullExample.php
Created March 11, 2019 13:00 — forked from IamSmith/FullExample.php
Fully working example
<?php
require_once("PHPExcel/PHPExcel.php");
$phpExcel = new PHPExcel();
$styleArray = array(
'font' => array(
'bold' => true,
)
);
@sany2k8
sany2k8 / access_postgresql_with_docker.md
Created March 11, 2019 10:10 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

@sany2k8
sany2k8 / gist:bad3927a7c37c51d518903719190e9d2
Created February 12, 2019 02:14 — forked from drorata/gist:146ce50807d16fd4a6aa
Minimal Working example of Elasticsearch scrolling using Python client
# Initialize the scroll
page = es.search(
index = 'yourIndex',
doc_type = 'yourType',
scroll = '2m',
search_type = 'scan',
size = 1000,
body = {
# Your query's body
})
@sany2k8
sany2k8 / csv_to_elastic_search_bulk_insert.py
Created January 31, 2019 17:14 — forked from clemsos/csv_to_elastic_search_bulk_insert.py
Elastic Search : index large csv files with Python Pandas
from pyelasticsearch import ElasticSearch
import pandas as pd
from time import time
root_path="/home/clemsos/Dev/mitras/"
raw_data_path=root_path+"data/"
csv_filename="week10.csv"
t0=time()
@sany2k8
sany2k8 / import_csv_to_db.py
Created December 30, 2018 14:56 — forked from weaming/import_csv_to_db.py
import_csv_to_db
# coding: utf8
"""
Goal: import csv to database.
pip install pandas, numpy
"""
import pandas
import numpy as np
@sany2k8
sany2k8 / useful_pandas_snippets.py
Last active December 29, 2018 16:32 — forked from fomightez/useful_pandas_snippets.py
Useful Pandas Snippets
# -*- coding: utf-8 -*-
# import pandas and numpy package
import numpy as np
import pandas as pd
# List unique values in a DataFrame column
df['Column Name'].unique()
# To extract a specific column (subset the dataframe), you can use [ ] (brackets) or attribute notation.
@sany2k8
sany2k8 / csv-to-pandas.py
Created December 29, 2018 16:00 — forked from jepma/csv-to-pandas.py
Pandas
import pandas as pd
# Read file
results = pd.read_csv("/tmp/data.csv", encoding='utf-8',sep=',', quoting=csv.QUOTE_ALL)
# Print rows
for row in results:
print(row)
# Iterate over rows
@sany2k8
sany2k8 / useful_pandas_snippets.md
Created December 29, 2018 15:48 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@sany2k8
sany2k8 / redis_cheatsheet.bash
Created October 7, 2018 15:14 — forked from LeCoupa/redis_cheatsheet.bash
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
redis-server /path/redis.conf # start redis with the related configuration file
redis-cli # opens a redis prompt
# Strings.