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
  • 19:22 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / course_outcome_itertools.py
Created July 29, 2016 21:40
While working on making an efficient way of getting the course ID if its list of outcomes includes an outcome with a specific ID, I came up with these monstrosities. In the end, they DO make a list that contains one item if there is a match. However, the one item is the outcome object itself, not the course ID. Maybe a little more clever code an…
x2 = list(itertools.ifilterfalse(lambda x: courseID if x.outcome.id != verifiedOutcome.id else False,
courseOutcomesJSONObjects)) # would yield help?
x2 = list(itertools.ifilterfalse(lambda x: x.outcome.id != verifiedOutcome.id,
courseOutcomesJSONObjects))
@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 / 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 / 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 / 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... ⌘,)

Here are my attempts to script an IntelliJ-based IDE.

IDE Scripting Console is backed by JSR-223 (javax.script.*) API.

Groovy, Clojure, JavaScript and other scripting languages may be used.

Open IDE Scripting Console, type a statement, hit Ctrl-Enter to execute the current line or selection.

.profile.language-extension file in the same directory will be executed along with it if present.

When using the flake8 program, it reads settings from the "[flake8]" section of tox.ini. When using the pycodestyle program (FKA pep8), it reads settings from the "[pep8]" (some sources say "[pycodestyle]") section of tox.ini. They are both places where one can put a "ignore=" setting with a list of error codes to be ignored by the respective programs.

Since developers are already used to this convention, why doesn't the Python plugin for IntelliJ IDEA follow it, too? I'm working with projects that have listed codes to be ignored in tox.ini, but IntelliJ IDEA still flags the violations in my code. I need to ignore each type of violation, one by one. What's worse, IntelliJ IDEA doesn't include the code when it gives the violation messages. So I end up copying the list of codes from tox.ini to the PEP8 inspection configuration in project settings.

This is an annoying waste of time.

@lsloan
lsloan / midnight.js
Created September 21, 2016 12:36
Using Node.js, get midnight for the current date and print as an ISO 8601 timestamp.
now=ISODate();
now.setHours(0,0,0,0);
midnight=now.toISOString();
print(midnight);
@lsloan
lsloan / wget vs. curl
Last active December 18, 2016 19:37
Using wget to fetch multiple URLs listed in a file. From http://blog.gypsydave5.com/2016/02/04/xargs-and-curl/
Gist title: "wget vs. curl"
Summary: Document comparing use of wget with curl.
@lsloan
lsloan / curl_url_file.txt
Created October 6, 2016 20:41
Using curl to fetch multiple URLs listed in a file. From http://blog.gypsydave5.com/2016/02/04/xargs-and-curl/
$ cat file-with-list-of-urls.txt | xargs -n 1 curl -LO