Skip to content

Instantly share code, notes, and snippets.

@jerowe
jerowe / airflow-docker-compose.yml
Last active June 15, 2023 06:29
Airflow Docker Compose Configuration - Includes airflow scheduler, airflow worker, airflow webserver, rabbitmq, and postgresql
version: '3'
# Run as
# docker-compose build; docker-compose up -d
# Check with
# docker ps
# Then check the logs with
# docker logs --tail 50 $container_id
# docker-compose images
# docker-compose logs --tail 20 repo_name
@reecelucas
reecelucas / scroll-progress.js
Created September 27, 2018 09:50
Scroll progress indicator in native JS
import debounce from "lodash/debounce";
const getPageHeight = () =>
Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight
);
@bayareawebpro
bayareawebpro / AutoMorphMap.php
Last active January 23, 2021 11:44
Automatic MorphMap for Laravel Models within a Namespace
<?php
$namespace = 'App\Models';
$models = array_filter(get_declared_classes(), function($index) use ($namespace) {
return strpos($index, $namespace) === 0;
});
$morphMap = array();
foreach($models as $class){
$mapName = snake_case(str_plural(class_basename($class)));
$morphMap[$mapName] = $class;
}
<?php declare(strict_types=1);
if (!\function_exists('array_map_recursive')) {
function array_map_recursive(array $array, callable $function): array
{
$out = [];
foreach ($array as $key => $value) {
$out[$key] = \is_array($value)
? array_map_recursive($value, $function)
: \call_user_func($function, $value, $key);
@yano3nora
yano3nora / spaceship_operator.php
Created July 26, 2018 14:47
[php: <=>] Spaceship operator on PHP 7. #php
/**
* Spaceship operator.
* @link https://qiita.com/Hiraku/items/62821d7d0e7af1ac211e
* @link https://teratail.com/questions/61222#reply-97259
*/
// 多次元配列の Diff
$arr1 = [
['flag' => 2, 'status' => 25],
['flag' => 64, 'status' => 25],
@itsMattShull
itsMattShull / server.js
Created June 26, 2018 04:19
Code for "HTTPS on localhost in Nuxt" blog post
const { Nuxt, Builder } = require('nuxt')
const app = require('express')()
const http = require('http')
const https = require('https')
const fs = require('fs-extra')
let server
const isProd = (process.env.NODE_ENV === 'production')
const port = process.env.PORT || 3000
@fomvasss
fomvasss / REST API.md
Last active April 14, 2025 16:50
Best practices Laravel Rest API

Best practices написание REST-API

  • Имена полей в ответе задавать в snake_case (prr_page, created_at, system_name,...)
  • Для времени использовать ISO 8601 (формат: YYYY-MM-DDTHH:MM:SSZ)
  • Отдавать данные (сам контент, поля сущностей, массивы сущностей), помещая их в data

Использование REST методов и примеры url'ов

  • GET: /api/users — получить список пользователей;
  • GET: /api/users/123 — получить указанного пользователя;
  • POST: /api/users — создать нового пользователя;
@sibiraj-s
sibiraj-s / verticalScrollPercentage.js
Last active June 23, 2020 19:54
Vertical Scroll Percentage
// include jQuery for this script to work
// or
// replace with vannila javascript where needed
var d = document.documentElement, b = document.body;
var scrollTop = d.scrollTop || b.scrollTop;
var scrollHeight = d.scrollHeight || b.scrollHeight;
var h = document.documentElement,
b = document.body,
// this code pauses and executes one after another
function five() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve("i am after five seconds"), 5000);
});
}
function three() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve("i am after three seconds"), 3000);
@bradtraversy
bradtraversy / pdo_db.php
Created February 21, 2018 12:56
PDO Class
<?php
/*
* PDO DATABASE CLASS
* Connects Database Using PDO
* Creates Prepeared Statements
* Binds params to values
* Returns rows and results
*/
class Database {
private $host = DB_HOST;