Skip to content

Instantly share code, notes, and snippets.

View chriswilkinsoncodes's full-sized avatar
✈️
where to next?

chris wilkinson chriswilkinsoncodes

✈️
where to next?
View GitHub Profile
@chriswilkinsoncodes
chriswilkinsoncodes / longest_prefix.py
Created August 30, 2021 05:29
solution to @cassidoo's "Interview question of the week" 2021-08-30
test_arrs = {
"arr1": ["cranberry","crawfish","crap"], # "cra"
"arr2": ["parrot", "poodle", "fish"], # ""
"arr3": [], # "error"
"arr4": ["", "", ""], # ""
"arr5": ["ab1d", "ab2d", "ab3d"], # "ab"
}
def longest_prefix(arr):
prefix = ""
// are there best practices that should apply here?
// my solution
const showEl = document.getElementById("show-item")
const itemEl = document.getElementById("item")
showEl.addEventListener("click", function() {
item.style.display = "block"
})
@chriswilkinsoncodes
chriswilkinsoncodes / this_example.js
Created May 22, 2021 22:45
Using "this" in Javascript
const celebrity = {
first: 'Robert',
last: 'Martin',
nickName: 'Uncle Bob',
fullName() {
const {first, last, nickName} = this;
console.log(`${first} ${nickName ? `[${nickName}] ` : ''}${last}`)
}
}
@chriswilkinsoncodes
chriswilkinsoncodes / 1_value.php
Last active April 24, 2021 20:02
PHP: call by value vs. call by reference
<?php
// call by value
function square($val) {
$val = $val * $val;
return $val;
}
$num = 7;
print($num);
@chriswilkinsoncodes
chriswilkinsoncodes / get.php
Created April 23, 2021 14:21
PHP: $_GET array and Null Coalescing Operator
<?php
function greet($username) {
print_r("hello, " . $username);
}
$username = $_GET['name'] ?? 'friend';
greet($username);
?>
@chriswilkinsoncodes
chriswilkinsoncodes / even_odd.php
Created April 20, 2021 14:23
ternary operator example in php
$num = 42;
$msg = ($num % 2 == 0) ? "Even" : "Odd";
echo "$msg \n";
@chriswilkinsoncodes
chriswilkinsoncodes / css_selectors.css
Created April 14, 2021 16:48
Examples of styling using class selectors vs type selectors
/* Example 1: class selectors */
.nav-links {
list-style: none;
}
.nav-link {
color: purple;
font-size: 1.5rem;
text-decoration: none;
}
.sample {
height: 300px;
width: 100%;
display: flex;
justify-content: center;
}
.sample > a {
display: inline-block;
height: 100%;
@chriswilkinsoncodes
chriswilkinsoncodes / console_log_tip.js
Created January 2, 2021 21:11
console.log tip - wrap variables in curly brackets to output as object
width = 100
length = 75
height = 50
console.log(width, length, height)
// 100 75 50
console.log({width, length, height})
// {width: 100, length: 75, height: 50}
@chriswilkinsoncodes
chriswilkinsoncodes / conditionals.js
Last active December 31, 2020 21:19
React: Use && with Conditionals
{ this.state.display && <h1>Display True!</h1> }
{ !this.state.display && <h1>Display False!</h1> }
{ (this.state.counter === 5) && <h1>Display Five!</h1> }