Skip to content

Instantly share code, notes, and snippets.

☠️
¯\_(ツ)_/¯

Corey Goldberg cgoldberg

☠️
¯\_(ツ)_/¯
Block or report user

Report or block cgoldberg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cgoldberg
cgoldberg / install-webdrivers.sh
Last active May 11, 2019
Selenium - download and install WebDriver binaries for Firefox (geckodriver) and Chrome (chromedriver)
View install-webdrivers.sh
#!/usr/bin/env bash
#
# Installer for WebDrivers
# ------------------------
# - Binary webdrivers are required to drive Firefox and Chrome browsers from Selenium.
# - This script will fetch the 64-bit binaries (geckodriver/chromedriver) for MacOS or Linux.
set -e
@cgoldberg
cgoldberg / geckodriver-install.sh
Last active Oct 21, 2019
download and install latest geckodriver for linux or mac (selenium webdriver)
View geckodriver-install.sh
#!/bin/bash
# download and install latest geckodriver for linux or mac.
# required for selenium to drive a firefox browser.
install_dir="/usr/local/bin"
json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
if [[ $(uname) == "Darwin" ]]; then
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("macos"))')
elif [[ $(uname) == "Linux" ]]; then
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64"))')
@cgoldberg
cgoldberg / pldiffs.md
Last active Apr 8, 2018
compare .plist changes between 2 git branches
View pldiffs.md

Comparing p-lists (iOS Property List Files)

In OS X and iOS programming frameworks, property list files are used to store information about bundles and applications. Analyzing .plist files can tell you a lot about an application. It is often useful to compare content and view modifications to .plist files to understand what has changed between versions of an application.


  • list paths of .plist files modified between 2 branches
View selenium-rum.py
"""
Instructions
************
1. install ubuntu deps:
-----------------------
sudo apt-get python-pip
sudo apt-get install firefox
sudo apt-get install chromium-browser
@cgoldberg
cgoldberg / num_cpu_cores.py
Created Nov 1, 2015
Find the number of CPU cores (Linux)
View num_cpu_cores.py
def num_cpu_cores():
with open('/proc/cpuinfo') as f:
return f.read().count('processor')
@cgoldberg
cgoldberg / got_root.py
Created Nov 1, 2015
check if the process is running as root (Unix/Linux)
View got_root.py
import os
def got_root():
"""check if we are running as root."""
if os.geteuid() == 0:
return True
return False
@cgoldberg
cgoldberg / bounce_services.sh
Created Oct 5, 2015
bounce supervisor controlled services
View bounce_services.sh
#!/bin/bash
# Bounce services and print start/stop messages to console and /var/log/syslog.
logger -s Restarting all processes controlled by supervisor now...
logger -s $(/usr/bin/supervisorctl restart all)
# Scheduled by system cron to run every hour:
# 0 */1 * * * /deploy/bounce_services.sh
@cgoldberg
cgoldberg / testing_databases.md
Last active Sep 28, 2015
Functional Tests - Database Setup
View testing_databases.md

SQLite as a test database?

One way to create isolate integration tests is to tear down and recreate database tables for every single test. This ensures every test starts with a clean and known state. However, achieving this with MySQL is an expensive (slow) operation and would add too much execution time between tests.

Tracelons uses SQLAlchemy as an ORM. Since the MySQL database is abtracted behind this layer, we could switch test database providers to SQLite. SQLite can be run in-memory, allowing fast teardowns of the test database. Coupled with fast schema creation, this enables very fast database operations during test runs.

However, there are some drawbacks to using SQLite as a replacement for MySQL during testing:

  • Some tooling in the tracelons repo is built specifically for MySQL and would require changes to work with SQLite.
  • SQLite does not have the same features, and does not enforce the same rules as MySQL. Therefore, it differs from production and could possibly allow tests to pass t
@cgoldberg
cgoldberg / recursive_file_info.py
Created Jun 20, 2015
walk a directory tree recursively. print total file count and size.
View recursive_file_info.py
#!/usr/bin/env python
#
# walk a directory tree recursively.
# print total file count and size.
# Corey Goldberg, 2015
import os
start_dir = '/mnt/wd-green/Tunes'
@cgoldberg
cgoldberg / grab-sessionid.py
Created May 11, 2015
grab session id from edX cookie
View grab-sessionid.py
def login(email, password, base_url='https://courses.edx.org'):
"""Login via HTTP and parse sessionid from the cookie."""
r = requests.get('{}/login'.format(base_url))
csrf = r.cookies['csrftoken']
payload = {'email': email, 'password': password}
cookies = {'csrftoken': csrf}
headers = {'referer': '{}/login'.format(base_url), 'X-CSRFToken': csrf}
r = requests.post('{}/user_api/v1/account/login_session/'.format(base_url),
data=payload, cookies=cookies, headers=headers)
try:
You can’t perform that action at this time.