Skip to content

Instantly share code, notes, and snippets.

View rlcarrca's full-sized avatar

Robert Carr rlcarrca

View GitHub Profile
import pandas as pd
def csv_to_excel(csv_file, excel_file):
df = pd.read_csv(csv_file)
df.to_excel(excel_file, index=False)
# Usage
csv_to_excel('data.csv', 'data.xlsx')
import time
import datetime
def countdown_timer(x, now=datetime.datetime.now):
target = now()
one_second_later = datetime.timedelta(seconds=1)
for remaining in range(x, 0, -1):
target += one_second_later
print(datetime.timedelta(seconds=remaining), 'remaining', end='\r')
time.sleep((target - now()).total_seconds())
def batch(seq, size):
return [
seq[i:i + size]
for i in range(0, len(seq), size)
]
seq = [1,2,3,4,5,6]
size = 3
# OUTPUT: [[1,2,3],[4,5,6]]
# Automate CSV
# pip install pandas
import pandas
# Read CSV File
data = pandas.read_csv("test.csv")
# Read CSV Specific Column
data = pandas.read_csv("test.csv", usecols=["col1", "col2"])
# Read CSV Specific Rows
data = pandas.read_csv("test.csv", nrows=5)
# Read CSV Specific Rows and Columns
@rlcarrca
rlcarrca / appear_most_often.py
Created September 17, 2025 01:19
Return the most frequent item that appears in a list
# returns the most frequent item that appears in the list:
def most_frequent(list):
return max(set(list), key = list.count)
numbers = [1,2,1,2,3,2,1,4,2]
x = most_frequent(numbers)
print(x)
@rlcarrca
rlcarrca / gist:c23890bfc429f625aa2c584420f3b3a9
Created September 6, 2025 01:13
Querying the information_schema (Postgres/CloudSQL)
SELECT column_name, data_type, character_maximum_length, is_nullable
FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'platform_logs';
{
"basics": {
"name": "Robert L Carr",
"label": "",
"picture": "",
"email": "[email protected]",
"phone": "(650) 430-5034",
"website": "http://registry.jsonresume.org/rlcarrca",
"summary": "An accomplished hands-on technologist offering over 20 years of demonstrated career success development. Experienced in all phases of software engineering and management from concept to continuing engineering: Market requirements, technology licensing, standards, architectural and engineering specifications, resource planning, recruiting, performance evaluations, budgets, scheduling, contract negotiation, customer support, etc.. Extensive experience leading operations for Technology and Application development within a diverse range of industries. Proven ability to conceptualize and deliver complex technology solutions. Strong understanding of the relationship between technology and strategic business interests. ",
"location": {
@rlcarrca
rlcarrca / app.py
Created February 23, 2018 16:11
Upload a file to the server using bottle
from __future__ import unicode_literals
import os
from bottle import route, request, static_file, run, response
@route('/')
def root():
return static_file('test.html', root='.')
@route('/upload', method='POST')
def do_upload():
def loadCommandLineArgs():
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--regen", help="Generate reports for all dates",
default=False, action="store_true")
return parser.parse_args()
@rlcarrca
rlcarrca / python-paged-ldap-snippet-2.4.py
Created August 18, 2017 21:58 — forked from mattfahrner/python-paged-ldap-snippet-2.4.py
This snippet allows you to do a Python LDAP search with paged controls. The latest version now supports Python "ldap" 2.4. Many thanks to Ilya Rumyantsev for doing the 2.4 legwork.
#! /usr/bin/python
import sys
import ldap
from ldap.controls import SimplePagedResultsControl
from distutils.version import LooseVersion
# Check if we're using the Python "ldap" 2.4 or greater API
LDAP24API = LooseVersion(ldap.__version__) >= LooseVersion('2.4')