Skip to content

Instantly share code, notes, and snippets.

View bahostetterlewis's full-sized avatar

Barrett bahostetterlewis

  • Zscaler
  • Chico, California
View GitHub Profile
@bahostetterlewis
bahostetterlewis / timdiff.sh
Created November 4, 2021 19:45
simple timediff in bash where a date was generated with date - useful for quick debugging
#!/usr/bin/env bash
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
s_t=d1-d2
hours=$((s_t / 3660))
s_t=$((s_t % 3600))
minutes=$((s_t / 60))
seconds=$((s_t % 60))
@bahostetterlewis
bahostetterlewis / fp.py
Created June 5, 2015 00:52
functional_solution.py
from __future__ import print_function, generators, division
from functools import partial
from itertools import imap
from operator import add
from visual import *
# Constants
K = 8.988e9
@bahostetterlewis
bahostetterlewis / phys.clj
Last active August 29, 2015 14:20
Simple Physics in Clojure
(defn point-builder [start stop step]
(if (< start stop)
(into (vector start) (point-builder (+ start step) stop step))
(vector start)
)
)
(defn half [n] (/ n 2) )
(defn linspace [size n]
@bahostetterlewis
bahostetterlewis / readme.md
Last active November 21, 2019 01:00
How to manually upload files to rackspace w/ Python 3

Uploading Files to Rackspace Cloud Files Using

Problem

Rackspace's officially supported python sdk is Pyrax - unfortunately it doesn't work with python3. There is the alternative apache module called libcloud but that is tricky to get working on windows.

Solution

Rackspace has a publically available api that can be used to manually send requests to your cloud files. All it requires is an existing container, a username, and an api key

To do this we will issue an initial request to rackspace with our credentials. Rackspace will then issue us a temporary token, and a list of services and urls to communicate with. We will pull our token and the cloudfiles services from this response and grab the url for our containers region (ie: DFW). Combine that url with our container and desired filename and we have the url we will upload our file to.

Setup the headers with our temporary token and content type and open the file we wish to send.

@bahostetterlewis
bahostetterlewis / copy_func.js
Last active August 29, 2015 14:16
Recipe for Using Formulas in Google Forms
// global
var ss = SpreadsheetApp.getActive();
function addRow() {
var sh = ss.getActiveSheet(), lRow = sh.getLastRow();
var lCol = sh.getLastColumn(), range = sh.getRange(lRow,lCol);
range.setValue("=SOME_FORMULA")
}
@bahostetterlewis
bahostetterlewis / prettyprintlxml.py
Created March 11, 2015 22:33
lxml python3 console pretty print
print(etree.tostring(root, encoding="UTF-8", xml_declaration=True, pretty_print=True).decode('UTF-8'))
@bahostetterlewis
bahostetterlewis / shared_folder_mount
Created January 20, 2015 18:59
This is how to mount a shared folder with write permissions in Ubuntu
sudo mount -t vboxsf -o rw,uid=1000,gid=1000,dmode=755,fmode=644 <sf name> <mount point>
@bahostetterlewis
bahostetterlewis / func_member_ptrs.cpp
Last active August 29, 2015 13:56
Creating a map of member functions example
#include <iostream>
#include <map>
using namespace std;
class node{
public:
node(int val){this->val = val; }
int val;
};
@bahostetterlewis
bahostetterlewis / main.py
Last active December 27, 2015 18:09
AI Question 2 multivariat regression CSCI 580
xs, ys, ws = [None, [1, 1, 2], [1, 2, -1], [1, 5, -2], [1, 3, -1], [1, 8, 2]], [None, -13, -4, 5, 0, 1], [1, 1, 1]
alpha = .01
def h(j):
return (ws[0] * xs[j][0]) + (ws[1] * xs[j][1]) + (ws[2] * xs[j][2])
def inner(inner_i):
return (xs[inner_j][inner_i] * (ys[inner_j] - hs[inner_j]) for inner_j in range(1, len(xs)))
@bahostetterlewis
bahostetterlewis / update-pip-advanced.py
Last active September 29, 2016 07:45
Update all pip packages!
#!/usr/bin/env python
import os
import pip
dists = []
for dist in pip.get_installed_distributions():
dists.append(dist.project_name)
for dist_name in sorted(dists, key=lambda s: s.lower()):