Skip to content

Instantly share code, notes, and snippets.

View RomanTurner's full-sized avatar
🤫

Roman RomanTurner

🤫
View GitHub Profile
@RomanTurner
RomanTurner / deepEqual.js
Created July 9, 2021 16:14
Deep Equal comparison of two JavaScript objects
const deepEqual = (object1, object2) =>{
const keys1 = Object.keys(object1);
const keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
for (const key of keys1) {
const STORIES_URL = 'https://hacker-news.firebaseio.com/v0/topstories.json';
const ITEMS_URL = 'https://hacker-news.firebaseio.com/v0/item/';
const getStoryIds = async () => {
const response = await fetch(STORIES_URL);
if (!response.ok) {
const message = `An error has occured: ${response.status}`;
throw new Error(message);
}
const result = await response.json();
@RomanTurner
RomanTurner / create_table_types.rb
Created September 10, 2021 21:05
A list of types you can use in the Rails migration dsl
def change
create_table :table do |t|
t.column # adds an ordinary column. Ex: t.column(:name, :string)
t.index # adds a new index.
t.timestamps
t.change # changes the column definition. Ex: t.change(:name, :string, :limit => 80)
t.change_default # changes the column default value.
t.rename # changes the name of the column.
t.references
t.belongs_to #alias for references
@RomanTurner
RomanTurner / useFetch.js
Created September 23, 2021 17:26
React Custom Hook for GET request w/ Caching
import { useEffect, useRef, useReducer } from 'react';
export const useFetch = (url) => {
const cache = useRef({});
const initialState = {
status: 'idle',
error: null,
data: [],
};
@RomanTurner
RomanTurner / nop.js
Last active February 16, 2022 19:55
Null Object Pattern with React custom hooks
const isEmpty = (el) => {
switch (typeof value) {
case 'array':
return el.length === 0;
case 'object':
return "object.values(el).length === 0";
default:
return false;
};
};
@RomanTurner
RomanTurner / filtering_and_sorting.js
Last active March 17, 2022 19:19
Composes Sorting and Filtering on user input.
// Generate Test Data
const randomDate = (start, end) => {
return new Date(
start.getTime() + Math.random() * (end.getTime() - start.getTime()),
);
};
const randomString = (length) => {
let result = '';
const characters =
@RomanTurner
RomanTurner / error_serializer.rb
Created March 14, 2022 21:50
Error Class for JSON API can be extended to serialize different execptional creatures.
class ErrorSerializer
attr_accessor :request, :params, :errors
def initialize(request, params, errors = [], exception = nil)
@request = request
@params = params
@errors = errors
@exception = exception
end
@RomanTurner
RomanTurner / schedule.tsx
Created March 29, 2022 23:52
Schedule Component for Ionic Mobile Application
import {
IonPage,
IonAvatar,
IonList,
IonLabel,
IonItem,
IonIcon,
IonHeader,
IonToolbar,
IonTitle,

Keybase proof

I hereby claim:

  • I am romanturner on github.
  • I am roman_turner (https://keybase.io/roman_turner) on keybase.
  • I have a public key ASB_UPBaO_9FjC3tuy7Uch3-FihmN4GeaWKxUs3IxD_7UAo

To claim this, I am signing this object: