Skip to content

Instantly share code, notes, and snippets.

View Lwdthe1's full-sized avatar

Lincoln W Daniel Lwdthe1

View GitHub Profile
@Lwdthe1
Lwdthe1 / usaCities.js
Last active April 13, 2024 14:18
JSON of 5,950+ USA Cities and Their States - Presented by https://www.ManyStories.com
[
{'city': 'Abbeville', 'state': 'Louisiana'},
{'city': 'Aberdeen', 'state': 'Maryland'},
{'city': 'Aberdeen', 'state': 'Mississippi'},
{'city': 'Aberdeen', 'state': 'South Dakota'},
{'city': 'Aberdeen', 'state': 'Washington'},
{'city': 'Abilene', 'state': 'Texas'},
{'city': 'Abilene', 'state': 'Kansas'},
@Lwdthe1
Lwdthe1 / euCities.js
Last active October 16, 2022 17:36
36 Largest European Cities By Population With Geographic Coordinates, in JSON Raw
//data from https://en.wikipedia.org/wiki/List_of_European_cities_by_population_within_city_limits
//The script
function runIt() {
var table = document.getElementsByClassName('wikitable sortable jquery-tablesorter')[0]
var cities = []
for (var i = 0, row; row = table.rows[i]; i++) {
if(i == 0) continue
//iterate through rows
//rows would be accessed using the "row" variable assigned in the for loop
var city = {}
@Lwdthe1
Lwdthe1 / PhotoScalerAndSaver.java
Last active January 15, 2022 02:03
A demonstration of three Java functions for scaling a photo's bitmap and saving it to a file without contorting the photo's dimensions. This is in response to this stackoverflow question: http://stackoverflow.com/questions/16060143/android-take-photo-and-resize-it-before-saving-on-sd-card/36210688#36210688
public class PhotoScalerAndSaver {
public static main(String[] args) {
//TODO: create your photo here
//Convert your photo to a bitmap
Bitmap photoBm = (Bitmap) "your Bitmap image";
//scale and save the photo to a file on the directory
saveScaledPhotoToFile(Bitmap photoBm)
@Lwdthe1
Lwdthe1 / #window.console.document()
Last active February 8, 2020 01:23
A helper function for teachers to console log to the HTML document.
(function() {
if (window.console.document) {
return
}
window.console.document = function() {
const args = Array.prototype.slice.call(arguments)
window.document.body.innerHTML = `<div id="__window_console_document__" style="padding:20px; font-size:20px; color: black">${args.join(' ')}</div>`
}
}())
@Lwdthe1
Lwdthe1 / mongoosePaging.js
Last active May 14, 2018 04:10
A function to page objects from MongoDb using Mongoose. It's pretty general, so the basic structure can be used in implementing paging on any database. I use this implementation to page some resources at https://www.smedian.com
Schema.statics._countByQuery = function(query) {
if(!query) {
throw new Error("query object is required")
}
return this.count(query)
.fail((err) => {
console.warn(err.message)
return Q.resolve(null)
})
@Lwdthe1
Lwdthe1 / extractAllMentionedUsernames.js
Last active January 15, 2018 03:12
A function to extract all mentioned @usernames from a string
function extractAllMentionedUsernames(str) {
var pattern = /\B@[a-z0-9_-]+/gi;
var arr = str.match(pattern) || []
return arr.map((u) => u.replace('@', ''))
}
// if str = '@lwdthe1 are you @lincoln_w_daniel?'
// extractAllMentionedUsernames(str) => ['lwdthe1', 'lincoln_w_daniel']
@Lwdthe1
Lwdthe1 / parseEntities.js
Last active January 15, 2018 02:15
Angular directive for parsing links and username mentions in text and converting to html elements
// example html: <p parse-entities data-parse-entities-url="_blank" data-parse-entities-mentions="true" ng-model="message.text"></p>
angularApp
.directive('parseEntities', function () {
var mentionPattern = /\B@[a-z0-9_-]+/gi;
var urlPattern = /[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/gi;
const VALID_ANCHOR_TARGETS = {'_self': '_self', '_blank': '_blank'}
VALID_ANCHOR_TARGETS['self'] = VALID_ANCHOR_TARGETS['_self']
VALID_ANCHOR_TARGETS['blank'] = VALID_ANCHOR_TARGETS['_blank']
return {
function convertCase(s, toDelim) {
if (!s || !s.length) return s
var existingType, lastFoundDelim = -1, camelCaseIndex = {}
if(s.indexOf(' ') > -1) existingType = ' ';
if(s.indexOf('-') > -1) existingType = '-';
if(s.indexOf('_') > -1) existingType = '_';
if(s.indexOf('.') > -1) existingType = '.';
if(!existingType) {
for(var i = 0; i < s.length; i++) {
@Lwdthe1
Lwdthe1 / selectBookmarks.js
Last active August 21, 2017 21:52
Select Chrome bookmarks to act on (delete, etc.) at chrome://bookmarks/#p=/me&hl=en-US
function run378268() {
var xcczxc = document.getElementsByClassName('col-list-checkbox')
for (var i = 0; i < xcczxc.length; i++) {
if(xcczxc[i].clicked == true) continue
xcczxc[i].click()
xcczxc[i].clicked = true
}
window.scroll(0,500)
}
var run378268Interval = setInterval(() => {
function copyTextToClipboard(text) {
var textArea = document.createElement("textarea");
//
// *** This styling is an extra step which is likely not required. ***
//
// Why is it here? To ensure:
// 1. the element is able to have focus and selection.
// 2. if element was to flash render it has minimal visual impact.
// 3. less flakyness with selection and copying which **might** occur if