Skip to content

Instantly share code, notes, and snippets.

View pg_cursor_example.rb
require 'pg'
db = PG.connect dbname: 'postgres'
db.exec("DROP DATABASE IF EXISTS just_fkn_around;")
db.exec("CREATE DATABASE just_fkn_around;")
db = PG.connect dbname: 'just_fkn_around'
define_method(:sql) { |sql| db.exec(sql).to_a }
sql <<-SQL
-- some data to query
@robsmith1776
robsmith1776 / crosstab.sql
Created Sep 13, 2020 — forked from romansklenar/crosstab.sql
PostgreSQL "pivot table" example using tablefunc extension
View crosstab.sql
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 Feb 27, 2020 — forked from waylan/subprocess_pipe.md
Writing to a python subprocess pipe
View subprocess_pipe.md

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 Jun 28, 2019 — forked from martic/SqlBackupToS3.ps1
Powershell Sql Backup To AWS S3
View SqlBackupToS3.ps1
# 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 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
View bash-cheatsheet.sh
#!/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 Apr 27, 2017 — forked from bryanbarnard/SimpleHttpClient.cs
Simple C# .NET 4.5 HTTPClient Request Using Basic Auth and Proxy
View SimpleHttpClient.cs
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
View 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 Oct 11, 2016 — forked from luke14free/sample_usage.py
Simple type checked objects in Python
View sample_usage.py
#!/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.
)
View delim.py
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 ";"
View Jinja Table.html
<div class="table-title">
<table class="table-fill">
<thead>
<tr>
{% for col in table[0] %}
<th>{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>