Skip to content

Instantly share code, notes, and snippets.

View DevEarley's full-sized avatar
🎯
Focusing

Alex Earley DevEarley

🎯
Focusing
View GitHub Profile
@DevEarley
DevEarley / angular-select.component.html
Last active June 17, 2020 23:49
Using ngModel to Select something with Angular. With disabled options, callback and default value.
<select [ngModel]="vm.selectedThing"
(ngModelChange)="onSelectThing($event)">
<option [value]="null">-</option>
<option *ngFor="let thing of vm.things"
[value]="thing.id"
[disabled]="thing.isDisabled">
{{thing.name}}
</option>
</select>
@DevEarley
DevEarley / AreRectanglesColliding.ts
Last active April 20, 2020 01:19
"AB" collision of two rectangles
type Rectangle = {
x: number,
y: number,
h: number,
w: number
}
function areRectanglesColliding(a: Rectangle, b: Rectangle) {
const i = a.x < (b.x + b.w);
const ii = b.x < (a.x + a.w);
@DevEarley
DevEarley / UsingNVM.md
Last active April 9, 2020 21:01
Using NVM
@DevEarley
DevEarley / arrayTo3DGrid.js
Last active March 29, 2020 23:25
Convert a 1D array into a 3D grid
function arrayTo3DGrid(xMax, yMax, zMax) {
let vertices = []
let totalVertices = xMax * yMax * zMax;
let xySquare = xMax * yMax;
for (let i = 0; i < totalVertices; i++) {
let x = i % xMax;
let z = Math.floor(i / (xySquare));
let ii = i - (z * xySquare);
let y = Math.floor(ii / xMax);
vertices.push(x, y, z);
@DevEarley
DevEarley / fix.py
Created January 26, 2020 01:59
Fix all files in a folder with python
import os
folder = 'D:\Projects\python\poems_need_fixing\\'
for filename in os.listdir(folder):
full_filename = folder+filename
print " START " + filename
r = open(full_filename,'r')
lines = r.readlines()
open(full_filename, "w").close()
@DevEarley
DevEarley / scraping.py
Last active January 8, 2020 03:02
Web Scraping with Python (2.7)
import requests
url = '<webpage address>'
page = requests.get(url)
from bs4 import BeautifulSoup
soup = BeautifulSoup(page.text, 'html.parser')
text = soup.find_all('h1')[0].get_text()
file = open('data.txt', 'w')
file.write(text)
file.close()
print(text)
@DevEarley
DevEarley / download-files-from-list.sh
Last active July 24, 2020 04:59
Download Multiple URLs with Bash
xargs -n 1 curl -L -O < list-of-files.txt
@DevEarley
DevEarley / OSColorScheme.css
Created December 30, 2019 04:38
User Preferred Color Scheme in CSS - OS Theme
:root {
--background-color: #fff;
--font-color: #000;
}
@media (prefers-color-scheme: light) {
:root {
--background-color: #fff;
--font-color: #000;
}
@DevEarley
DevEarley / OSColorScheme.css
Created December 30, 2019 04:38
User Preferred Color Scheme in CSS - OS Theme
:root {
--background-color: #fff;
--color: #000;
}
@media (prefers-color-scheme: light) {
:root {
--background-color: #fff;
--color: #000;
}
@DevEarley
DevEarley / count-lines.sh
Created December 27, 2019 16:26
Counts LOC for all files in a folder
find . -name '*.*' | xargs wc -l