Skip to content

Instantly share code, notes, and snippets.

@jadudm
Created May 29, 2020 12:42
Show Gist options
  • Save jadudm/c576a55ed6ee6977a1ff89373babbf31 to your computer and use it in GitHub Desktop.
Save jadudm/c576a55ed6ee6977a1ff89373babbf31 to your computer and use it in GitHub Desktop.
Counting usages of $( in files as a way of estimating JQuery usage.
import os
import re
root = "."
list_of_files = []
file_count = 0
ignore_extensions = ["sh", "md", "png", "otf", "woff2", "ttf", "woff", "eot", "ico", "jpg", "sample"]
for root, directory_names, file_names in os.walk(root):
for fname in file_names:
regex = "$|".join(ignore_extensions)
if (not re.search(regex, fname)):
list_of_files.append(os.path.join(root, fname))
jquery_use = 0
for filepath in list_of_files:
try:
with open(filepath, "r") as a_file:
# Start at zero, can increment at top of loop
line_number = 0
for line in a_file:
line_number += 1
stripped = line.strip()
if re.search("\\$\\(", stripped):
print(filepath)
print("-----------------------------")
print(line_number, stripped)
print()
jquery_use += 1
except:
pass
print(jquery_use)
@jadudm
Copy link
Author

jadudm commented May 29, 2020

The try/catch was because I got tired of excepting binary files.

@jadudm
Copy link
Author

jadudm commented May 29, 2020

In tock, there are 55 uses of "$(".

./tock/tock/tests/js/timecard.test.js
-----------------------------
24 const entries = await page.$$('.entry');

./tock/tock/tests/js/timecard.test.js
-----------------------------
27 const _entries = await page.$$('.entry');

./tock/tock/static/js/components/timecard.js
-----------------------------
9 return $('.entry').map((i, entry) => {

./tock/tock/static/js/components/timecard.js
-----------------------------
10 const markedForDeletion = $('.entry-delete input', entry).prop('checked');

./tock/tock/static/js/components/timecard.js
-----------------------------
16 const project = parseInt($('.entry-project select', entry).val(), 10) || null;

./tock/tock/static/js/components/timecard.js
-----------------------------
19 const hours = parseFloat($('.entry-amount input', entry).val()) || 0;

./tock/tock/static/js/components/timecard.js
-----------------------------
62 $('.entries .entry').each(function (i, entry) {

./tock/tock/static/js/components/timecard.js
-----------------------------
63 entry = $(entry);

./tock/tock/static/js/components/timecard.js
-----------------------------
64 var project = $('.entry-project select', entry).val();

./tock/tock/static/js/components/timecard.js
-----------------------------
65 var hours = $('.entry-amount input', entry).val();

./tock/tock/static/js/components/timecard.js
-----------------------------
75 const totalElement = $('.entries-total-reported-amount');

./tock/tock/static/js/components/timecard.js
-----------------------------
76 const billableElement = $('.entries-total-billable-amount');

./tock/tock/static/js/components/timecard.js
-----------------------------
78 $('.fill', totalElement).attr('stroke-dasharray', `${totals.totalHours / totalHoursTarget} 1`)

./tock/tock/static/js/components/timecard.js
-----------------------------
79 $('.fill', billableElement).attr('stroke-dasharray', `${totals.billableHours / totals.billableHoursTarget} 1`)

./tock/tock/static/js/components/timecard.js
-----------------------------
81 $('.number-label', totalElement).html(totals.totalHours);

./tock/tock/static/js/components/timecard.js
-----------------------------
82 $('.number-label', billableElement).html(totals.billableHours);

./tock/tock/static/js/components/timecard.js
-----------------------------
106 var $fieldset = $(selectBox).parents('.entry-project'),

./tock/tock/static/js/components/timecard.js
-----------------------------
107 $selected = $(selectBox).find(':selected'),

./tock/tock/static/js/components/timecard.js
-----------------------------
120 var $fieldset = $(selectBox).parents('.entry-project'),

./tock/tock/static/js/components/timecard.js
-----------------------------
121 $selected = $(selectBox).find(':selected'),

./tock/tock/static/js/components/timecard.js
-----------------------------
158 if ($('div.entry:last .entry-project select').val() !== '') {

./tock/tock/static/js/components/timecard.js
-----------------------------
159 $(".add-timecard-entry").click();

./tock/tock/static/js/components/timecard.js
-----------------------------
166 $("div.entry:last .entry-project select").val(line.project);

./tock/tock/static/js/components/timecard.js
-----------------------------
167 $("div.entry:last .entry-project select").trigger("chosen:updated");

./tock/tock/static/js/components/timecard.js
-----------------------------
170 $("div.entry:last .entry-amount input").val(line.hours);

./tock/tock/static/js/components/timecard.js
-----------------------------
171 $("div.entry:last .entry-amount input").change();

./tock/tock/static/js/components/timecard.js
-----------------------------
180 $("div.entry:last select").change();

./tock/tock/static/js/components/timecard.js
-----------------------------
185 $("body").on("keyup", ".entry-amount input", function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
189 $("body").on("click", ".entry-amount input, .entry-delete input", function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
194 $("body").on("change", ".entry-project select", function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
199 $(document).ready(function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
205 $("#save-timecard").on("click", function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
210 var form = $('form'),

./tock/tock/static/js/components/timecard.js
-----------------------------
217 $("#submit-timecard").on("click", function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
222 $('form').submit();

./tock/tock/static/js/components/timecard.js
-----------------------------
225 $(".add-timecard-entry").on("click", function () {

./tock/tock/static/js/components/timecard.js
-----------------------------
226 $('div.entry:last').clone().each(function (i) {

./tock/tock/static/js/components/timecard.js
-----------------------------
227 var entry = $(this);

./tock/tock/static/js/components/timecard.js
-----------------------------
247 var formItem = $(this);

./tock/tock/static/js/components/timecard.js
-----------------------------
265 $('div.entry:last').find('.entry-project select')

./tock/tock/static/js/components/timecard.js
-----------------------------
273 $('#id_timecardobjects-TOTAL_FORMS').val(parseInt($('#id_timecardobjects-TOTAL_FORMS').val()) + 1);

./tock/tock/static/js/components/timecard.js
-----------------------------
283 $('.entries .entry').each(function (i, entry) {

./tock/tock/static/js/components/timecard.js
-----------------------------
284 entry = $(entry);

./tock/tock/static/js/components/timecard.js
-----------------------------
285 var project = $('.entry-project select', entry).val();

./tock/tock/static/js/components/timecard.js
-----------------------------
291 $('.entry-amount input', entry).val(Number(fromStorage[storageIndex].hours));

./tock/tock/static/js/components/timecard.js
-----------------------------
307 $('.entry-project select')

./tock/tock/static/js/components/timecard.js
-----------------------------
316 $('.entry-project select').trigger('change');

./tock/tock/static/js/components/timecard.js
-----------------------------
321 $('form').on('focus', 'input[type=number]', function (e) {

./tock/tock/static/js/components/timecard.js
-----------------------------
322 $(this).on('mousewheel.disableScroll', function (e) {

./tock/tock/static/js/components/timecard.js
-----------------------------
327 $('form').on('blur', 'input[type=number]', function (e) {

./tock/tock/static/js/components/timecard.js
-----------------------------
328 $(this).off('mousewheel.disableScroll');

./tock/tock/templates/hours/reporting_period_form.html
-----------------------------
18 $(function() {

./tock/tock/templates/hours/reporting_period_form.html
-----------------------------
19 $( ".datepicker" ).datepicker();

./tock/tock/templates/employees/user_detail.html
-----------------------------
35 $(function() {

./tock/tock/templates/employees/user_detail.html
-----------------------------
36 $( ".datepicker" ).datepicker();

55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment