Skip to content

Instantly share code, notes, and snippets.

View lsloan's full-sized avatar

Mr. Lance E Sloan «UMich» lsloan

  • Teaching and Learning (@tl-its-umich-edu) at University of Michigan: Information and Technology Services
  • Ann Arbor, Michigan, USA
  • 06:18 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / README.md
Last active May 7, 2022 09:27
Python/IntelliJ IDEA 2016: Add virtual environment as SDK and specify as default for module

Using:

  • IntelliJ IDEA 2016.1.3 (Build #IU-145.1617, built on June 3, 2016)
  • Python (Version: 2016.1.145.266) plugin

Adding Python virtualenv as new SDK

  • Select menu item: File > Project Structure... ⌘;

Note: In PyCharm instructions, this UI is part of the Preferences (IntelliJ IDEA > Preferences... ⌘,)

@lsloan
lsloan / new_window_focus.md
Created August 16, 2016 17:19
JavaScript: Focus on a newly opened window or tab.

Many web browsers will let JavaScript code open a new window (or tab) using the Window class. However, whether the new view is shown as a window or tab cannot be specified by JS. It is entirely under the control of the browser, which may let the user specify how new windows should appear. Rightfully so, the user should be in control of their environment.

However, not all browsers will focus on the new view after it opens. For example, if the user specifies that Google Chrome should open new windows as tabs, those new tabs will be loaded in the background. The user will not see the contents until they explicitly select that tab for viewing.

@lsloan
lsloan / ObjectsFromJSON.md
Last active August 9, 2016 14:05
Python: The solution I use to get objects from JSON.

Note: This code and documentation are incomplete.

@lsloan
lsloan / github_whitespace_button.user.js
Last active August 5, 2016 20:04 — forked from xPaw/github_whitespace_button.user.js
Add a button in GitHub UI to ignore whitespace in diffs. To install in a browser with a UserScript extension (e.g., Tampermonkey), click the "Raw" button.
// ==UserScript==
// @name Ignore whitespace button on GitHub
// @description Adds a button in GitHub UI to ignore whitespace changes in commits
// @author lsloan
// @namespace https://gist.github.com/lsloan/e51ac64706b86cc1942616004f2be3bd
// @updateURL https://gist.github.com/lsloan/e51ac64706b86cc1942616004f2be3bd/raw/github_whitespace_button.user.js
// @match https://github.com/*
// @version 1.5
// @run-at document-end
// @grant none
@lsloan
lsloan / requests_extension.py
Created July 26, 2016 21:33
Python: This seemed like a clever way to allow my extension to requests to accept a URI containing named parameters. If the URI still contained the parameters by the time it received them, it would use the method's keyword arguments to replace them. However, being careful to pass along `**kwargs` turned out to be a problem. If the keyword argume…
def get(self, apiQueryURI, params=None, **kwargs):
"""
Append the specified query URI to the base URL, which is then sent to the REST API.
Results are returned as a requests.Response object.
:param apiQueryURI: URI for the query, to be appended to the base URL
:type apiQueryURI: str
:return: requests.Response
:rtype: requests.Response
"""
@pdanford
pdanford / README.md
Last active April 14, 2025 05:44
Launching iTerm2 from macOS Finder

Launching iTerm2 from macOS Finder

(Based on info from Peter Downs' gitub but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)

The following three ways to launch an iTerm2 window from Finder have been tested on iTerm2 version 3+ running on macOS Mojave+.

pdanford - April 2020


@lsloan
lsloan / urltidy.py
Created July 8, 2016 20:45
Python experiments in removing contiguous slashes from URLs. The `urlparse` module should do this.
"""
Experiments in removing contiguous slashes in URLs.
Why doesn't urlparse do this for us?
"""
import posixpath
import re
import urlparse
apiBaseURL = 'http://example.org//api/v1/'
@lsloan
lsloan / jython_explore_java.md
Last active August 12, 2016 21:46
A guide to using Jython for exploring the Java environment of a project managed with Maven.

Use Jython To Explore Java

When I develop with Python, I like to use its interactive interpreter to experiment with code samples quickly and in real time. It allows me to import the code I've been developing so I can test it in a controlled environment. Java doesn't include this ability outnatively, but there are a number of ways to accomplish something similar with additional software. With my preference for Python, I chose Jython to do this.

  1. Install Jython. See jython.org for details. It may be as simple as, for example, on OS X with Homebrew:
brew install jython
@lsloan
lsloan / Vim Markdown support.md
Last active June 21, 2016 20:38
My vim environment that does a pretty good job with showing formatting as one edits markdown and keeps my preferred behavior.

An example of configuring Vim to support Markdown.

@lsloan
lsloan / string_comparison_example.php
Last active June 15, 2016 19:36
PHP: Avoid the equal ("==") comparison operator for comparing strings that may be numeric.
<?php
/*
* When using the equal comparison operator ("==") to compare a number with a string or
* the comparison involves numeric strings, each string is converted to a number and the
* comparison performed numerically. These rules also apply to the switch statement. The
* type conversion does not take place when using the identical comparison operator
* ("===") as that involves comparing the type as well as the value.
*
* It's safer to always use strcmp() or the identical comparison operator ("===") for
* string comparisons.