Skip to content

Instantly share code, notes, and snippets.

View psenger's full-sized avatar
:octocat:
Makin Bacon

Philip A Senger psenger

:octocat:
Makin Bacon
View GitHub Profile
@psenger
psenger / somResponsiveComponent.js
Last active November 4, 2020 22:42
[Responsive Window Resize Event with ReactJS] #ReactJs #JavaScript
import React from "react";
function someResponsiveComponent() {
const {height,width} = windowResizeEventListener();
return (
<p>
The window <span>height = {height}</span><span>width = {width}</span>
</p>
);
}
@psenger
psenger / README.md
Last active August 14, 2023 06:08
[React Hooks] #ReactJs #JavaScript
@psenger
psenger / add.js
Last active November 12, 2021 03:55
[How to make a Node Module run on Command Line and Required] #JavaScript
#!/usr/local/bin/node
#!/usr/bin/env node
const add = ( first, second ) => {
return parseInt( first ) + parseInt( second );
}
/**
allows the javascript to be executed like this
[14:08:27]/tmp $ ./add.js 1 2
@psenger
psenger / sell.js
Last active December 23, 2020 09:53
[Example of messages in discord] #JavaScript #Discord
const {prefix} = require('../config.json');
/**
* Usage string template.
*/
const usage = '<artifact quantity> <artifact level> <mention buyer>';
/**
* The Agree Message
* @param {string} seller - the Seller's name
@psenger
psenger / Readme.md
Last active January 8, 2021 05:42
[How to merge two dictionaries in Python] #Python

How to merge two dictionaries in Python with the ** operator

The ** operator adds key-value pairs to the new dict.. its that simple.

a = dict()
b = dict()

a[1] = { id:1, 'name': 'bob' }
a[2] = { id:2, 'name': 'larry' }
@psenger
psenger / giverole.py
Created January 10, 2021 05:37
[Discord Give Role] #Python #Discord
from discord.utils import get
@client.command(pass_context=True)
async def giverole(ctx, member: discord.Member, *, role: discord.Role):
check_role = get(ctx.message.server.roles, name='Board of Executives')
if check_role not in member.roles:
await client.say(f"You don't have the role '{str(role)}'")
else:
await client.add_roles(member, role)
await client.say(f"The role '{str(role)}' has been given to {member.mention}.")
@psenger
psenger / example_parameterized_jest_describe.spec.js
Last active January 21, 2021 02:19
[Jest - How to Parameterized Tests and Describes] #Jest #JavaScript
const not = val => !val;
// How to parameterize describe in jest
describe("index", () => {
describe.each([
['boolean', true, false],
['boolean', false, true],
['number', 0, true],
['number', 1, false],
['number', 999, false],
['number', -1, false],
@psenger
psenger / index.spec.js
Last active January 19, 2021 00:11
[Jest - How to Monitor Console] #Jest
const warnConsole = jest.spyOn(console, "warn").mockImplementation(() => {});
const errorConsole = jest.spyOn(console, "error").mockImplementation(() => {});
const infoConsole = jest.spyOn(console, "info").mockImplementation(() => {});
expect(warnConsole).toBeCalledWith('...');
expect(errorConsole).toBeCalledWith('...');
expect(infoConsole).toBeCalledWith('...');
expect(warnConsole).not.toHaveBeenCalled();
expect(errorConsole).not.toHaveBeenCalled();
@psenger
psenger / mask.js
Last active April 6, 2021 23:57
[Masking / Plucking - Omitting / Copying Keys / Values from an Object Literal into another Object Literal] #LoDash #JavaScript
/**
* mask values from an object (inverse of pluck).
* @param {Object} [obj={}] - an Object, null and undefined return an empty obj literal.
* @param {[String]} [keys=[]] - an array of keys to mask/remove from the object.
* @return {Object}
*/
const mask = (obj = {}, keys = []) => Object.keys(obj).reduce((ac, key) => {
ac[key] = (keys.some((p)=>(p===key))) ? void 0 : obj[key];
return ac;
}, {});
@psenger
psenger / ReadME.md
Last active November 19, 2023 00:24
[ERR_TLS_CERT_ALTNAME_INVALID] #NodeJS

ERR_TLS_CERT_ALTNAME_INVALID indicates self signed TLS error.

Obsured by the following where xxxx.xxx.com can be a variety of host names.

Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:xxxx.xxx.com\",\"cause\":{\"reason\":\"Host: localhost. is not in the cert's altnames: DNS:xxxx.xxx.com,

Option one