Skip to content

Instantly share code, notes, and snippets.

@robsmith1776
robsmith1776 / crosstab.sql
Created September 13, 2020 12:33 — forked from romansklenar/crosstab.sql
PostgreSQL "pivot table" example using tablefunc extension
CREATE EXTENSION tablefunc;
CREATE TABLE sales(year int, month int, qty int);
INSERT INTO sales VALUES(2007, 1, 1000);
INSERT INTO sales VALUES(2007, 2, 1500);
INSERT INTO sales VALUES(2007, 7, 500);
INSERT INTO sales VALUES(2007, 11, 1500);
INSERT INTO sales VALUES(2007, 12, 2000);
INSERT INTO sales VALUES(2008, 1, 1000);
INSERT INTO sales VALUES(2009, 5, 2500);
@robsmith1776
robsmith1776 / subprocess_pipe.md
Created February 27, 2020 19:00 — forked from waylan/subprocess_pipe.md
Writing to a python subprocess pipe

Here's a few things I tried to write output to a python subprocess pipe.

from subprocess import Popen, PIPE

p = Popen('less', stdin=PIPE)
for x in xrange(100):
    p.communicate('Line number %d.\n' % x)
@robsmith1776
robsmith1776 / SqlBackupToS3.ps1
Created June 28, 2019 18:42 — forked from martic/SqlBackupToS3.ps1
Powershell Sql Backup To AWS S3
# Needed PS packages
# Install-Package -Name pscx
# Install-Package -Name AWSPowerShell
#
# Scheduling
# The script then needs to be scheduled to run every night, I’m using scheduled tasks for this,
# creating a task that runs nightly and triggers the powershell script by running
# Powershell.exe with the arguments 
# -ExecutionPolicy Bypass C:\SqlBackup\SqlBackupToS3.ps1.
# From <https://www.rhysgodfrey.co.uk/b/blog/posts/backing-up-a-sql-database-to-amazon-s3-using-powershell>
@robsmith1776
robsmith1776 / bash-cheatsheet.sh
Created May 20, 2019 20:12 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@robsmith1776
robsmith1776 / SimpleHttpClient.cs
Created April 27, 2017 14:42 — forked from bryanbarnard/SimpleHttpClient.cs
Simple C# .NET 4.5 HTTPClient Request Using Basic Auth and Proxy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net;
namespace HTTP_Test
@robsmith1776
robsmith1776 / download_python_requests.py
Created October 21, 2016 21:31
download_python_requests.py
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
#f.flush() commented by recommendation from J.F.Sebastian
return local_filename
@robsmith1776
robsmith1776 / sample_usage.py
Created October 11, 2016 22:20 — forked from luke14free/sample_usage.py
Simple type checked objects in Python
#!/usr/bin/env python
from type_checked_entities import entity_factory
Giraffe = entity_factory( # let's define what is a giraffe!
"giraffe",
name=str, # my name is a string
age=float, # my age is an int
eats=object, # I eat pretty much everything.
)
def detectDelimiter(csvFile):
with open(csvFile, 'r') as myCsvfile:
header=myCsvfile.readline()
if header.find(";")!=-1:
return ";"
if header.find(",")!=-1:
return ","
#default delimiter (MS Office export)
return ";"
<div class="table-title">
<table class="table-fill">
<thead>
<tr>
{% for col in table[0] %}
<th>{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
@robsmith1776
robsmith1776 / WriteDataTableFunc.cs
Last active April 20, 2016 18:31
Function to Write to DataTables
public void WriteClickLinks(DataTable dt, string filepath)
{
StreamWriter output = new StreamWriter(filepath);
StringBuilder sb = new StringBuilder();
using (output)
{
foreach (DataColumn col in dt.Columns)
{