Skip to content

Instantly share code, notes, and snippets.

@SergeyMell
SergeyMell / gallery.js
Created April 30, 2022 20:04
Infinite image gallery core js
@SergeyMell
SergeyMell / index.html
Last active April 24, 2022 20:10
Infinite image carousel - basic layout
<div class="gallery__container">
<img src="https://images.unsplash.com/photo-1602116224649-c3b66d507eef?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80" class="gallery__item"/>
<img src="https://images.unsplash.com/photo-1597816165828-56c53e9394f4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80" class="gallery__item"/>
<img src="https://images.unsplash.com/photo-1590080603530-ab883f5f5763?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80" class="gallery__item"/>
<img src="https://images.unsplash.com/photo-1574352524385-e8eb66309d43?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80" class="gallery__item"/>
<img src="https://images.unsplash.com/photo-1610878180933-123728745d22?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80" class="gallery__item"/>
<img src="http
@SergeyMell
SergeyMell / interface.converter.ts
Created September 5, 2021 14:48
Convert server response into Typescript interface
// Main function
function convertToInterface(obj) {
  const resObj = {};
  for (let key in obj) {
    if (typeof obj[key] === 'string') {
      resObj[key] = 'string';
    } else if (typeof obj[key] === 'number') {
      resObj[key] = 'number';
    } else if (typeof obj[key] === 'boolean') {
      resObj[key] = 'boolean';
@SergeyMell
SergeyMell / property-item.tsx
Created September 17, 2020 22:20
TypeORM joined tables in AdminBro back office
import * as React from 'react';
import { Box } from 'admin-bro'
const PropertyItem = (props) => {
const { join, param } = props.property.custom;
return (
<Box>{props.record.populated[join].params[param]}</Box>
)
@SergeyMell
SergeyMell / property-item.tsx
Created September 17, 2020 22:17
TypeORM joined tables in AdminBro back office - Post Resource with custom params
import { ResourceWithOptions } from 'admin-bro';
import { Post } from '../../models/posts/entities/post.entity';
import AdminBro from 'admin-bro';
const PostResource: ResourceWithOptions = {
resource: Post,
options: {
properties: {
userLink: {
custom: {
@SergeyMell
SergeyMell / property-item.tsx
Created September 17, 2020 22:04
TypeORM joined tables in AdminBro back office - PropertyItem component
import * as React from 'react';
import { Box } from 'admin-bro'
const PropertyItem = (props) => {
return (
<Box>{props.record.populated.userId.params.link}</Box>
)
}
export default PropertyItem;
@SergeyMell
SergeyMell / post.resource.ts
Created September 17, 2020 22:00
TypeORM joined tables in AdminBro back office - Post resource
import { ResourceWithOptions } from 'admin-bro';
import { Post } from '../../models/posts/entities/post.entity';
import AdminBro from 'admin-bro';
const PostResource: ResourceWithOptions = {
resource: Post,
options: {
properties: {
userLink: {
components: {
@SergeyMell
SergeyMell / post.entity.ts
Last active September 14, 2020 05:44
TypeORM joined tables
@Entity('posts')
export class Post extends BaseEntity {
@PrimaryColumn({
name: 'pk_post',
generated: 'increment',
})
id: number; // <= Should always be `id`
...
@SergeyMell
SergeyMell / user.entity.ts
Last active September 13, 2020 18:04
TypeORM joined tables
import { BaseEntity, Column, Entity, OneToMany, PrimaryColumn } from 'typeorm';
import { UseAsTitle } from 'admin-bro-typeorm';
import { Post } from '../../posts/entities/post.entity';
@Entity('users')
export class User extends BaseEntity {
@PrimaryColumn({
name: 'pk_user',
generated: 'increment',
import { ResourceWithOptions } from 'admin-bro';
import { User } from '../../users/entities/user.entity';
const UserResource: ResourceWithOptions = {
resource: User,
options: {},
};
export default UserResource;