Skip to content

Instantly share code, notes, and snippets.

View dennisja's full-sized avatar
🕊️
I have learned that I have a lot to learn

dj dennisja

🕊️
I have learned that I have a lot to learn
View GitHub Profile
@dennisja
dennisja / snakeToCamelCase.ts
Created April 27, 2023 17:47
A typescript generic that converts object keys from snake to camelCase
type SnakeToCamelCase<
SnakeCaseWord extends string,
Result extends string = ''
> = Uncapitalize<
SnakeCaseWord extends `${infer Head}_${infer Tail}`
? SnakeToCamelCase<Tail, `${Result}${Capitalize<Head>}`>
: `${Result}${Capitalize<SnakeCaseWord>}`
>;
type CamelCaseObjectTypes<O extends object> = {
@dennisja
dennisja / objects.js
Last active June 7, 2019 19:46
Implements and uses functions to calculate the averageRanking of objects and to sort objects by ranking
/**
* Sorts an array of object by ranking
* @param {array} objects The array containing objects to sort by ranking
*/
function orderByRanking(objects) {
return objects.sort((a, b) => a.ranking - b.ranking);
}
/**
* Calculates the average ranking of objects
@dennisja
dennisja / pluralsight video downloader.js
Last active April 17, 2020 12:23
A simple script to download pluralsight courses in the browser console.
// open all sections
$$('section.module:not(.open) header').forEach((h) => h.click());
// get all list course videos in each section
let listItems = $$('section.module li');
// download them
for (let i = 0; i < listItems.length; i++) {
let listItem = listItems[i];
let title = listItem.querySelector('h3').textContent;
@dennisja
dennisja / 1.js
Created March 5, 2019 08:28 — forked from getify/1.js
creating hard-bound methods on classes
class Foo {
constructor(x) { this.foo = x; }
hello() { console.log(this.foo); }
}
class Bar extends Foo {
constructor(x) { super(x); this.bar = x * 100; }
world() { console.log(this.bar); }
}
@dennisja
dennisja / currency.sql
Created December 30, 2018 12:53 — forked from allanlaal/currency.sql
SQL table of World currencies (even some expired ones) Source: http://bcmoney-mobiletv.com/blog/2008/12/30/currency-codes-dropdown-and-sql-table/ Cleaned up a bit, uses InnoDB and iso currency code as the PRIMARY key
--
-- Table structure for table `currency`
--
CREATE TABLE IF NOT EXISTS `currency` (
`iso` char(3) CHARACTER SET utf8 NOT NULL DEFAULT '',
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`iso`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
import React from "react";
// get the MockedProvider from react-apollo/test-utils
import { MockedProvider } from "react-apollo/test-utils";
import { cleanup, render } from "react-testing-library";
import UsersList, { GET_USERS_QUERY } from "./UserList";
describe("UserList component", () => {
afterEach(cleanup);
const request = {
it('should render the loading component', () => {
const { getByText } = render(
// pass empty array to mocks prop
<MockedProvider mocks={[]}>
<UsersList />
</MockedProvider>
);
// find loading component by text
const loader = getByText(/Loading/);
// check whether that it renders the right content
import React from "react";
// get the MockedProvider from react-apollo/test-utils
import { MockedProvider } from "react-apollo/test-utils";
import { cleanup, render } from "react-testing-library";
// get the UserList component and GET_USERS_QUERY
// if the UserList file is in the same direcory as a file with the file containing the tests
import UsersList, { GET_USERS_QUERY } from "./UserList";
describe("UserList component", () => {
import { render } from 'react-testing-library';
import { ApolloProvider } from 'react-apollo';
import client from './apolloClient';
describe("UserList component", () => {
it("should render the list of users", () => {
// try rendering the UserList component in an ApolloProvider
const { getByText } = render(
import { render } from 'react-testing-library';
describe("UserList component", () => {
it("should render the list of users", () => {
// try rendering the UserList component
const { getByText } = render(<UsersList />);
});
});