Skip to content

Instantly share code, notes, and snippets.

dir = File.expand_path("..", __FILE__)
require File.join(dir, "redis_protocol")
require 'pp'
class APIFront
GEM_STORE = "http://production.s3.rubygems.org"
@c80609a
c80609a / php_decorator.md
Created May 7, 2025 15:38
php_decorator.md

В PHP можно реализовать функциональность, аналогичную декораторам в Python, с помощью функций высшего порядка или классов. Декораторы в Python позволяют обернуть одну функцию другой, добавляя дополнительное поведение. В PHP это можно сделать следующим образом:

Пример с использованием функций

<?php
function decorator($function) {
    return function() use ($function) {
        echo "Before function call\n";
        $function();

RAILS_RELATIVE_URL_ROOT

Rails

By default RAILS_RELATIVE_URL_ROOT is used only for asset pipeline.

To namespace your rails routes you need to wrap run MyApp::Application with map in your config.ru:

map ENV['RAILS_RELATIVE_URL_ROOT'] || "/" do
@c80609a
c80609a / answer.md
Created April 27, 2025 15:05
answer.md

To address the issue where an unauthorized request to http://127.0.0.1:8080/rb/admin results in a 404 error instead of routing to the desired path, you need to ensure that your Rails application is correctly configured to handle requests with the /rb prefix. Here are some steps you can take:

  1. Ensure Rails is Aware of the Prefix:

    In your application.rb file, you have already set the config.action_controller.relative_url_root to /rb. This is correct, but ensure that this setting is being applied correctly in your environment.

  2. Check Your Routes:

    Make sure that your Rails routes are set up to handle requests with the /rb prefix. You might need to adjust your routes to account for this prefix. For example, you can use a scope in your routes.rb file:

@c80609a
c80609a / code.md
Created April 1, 2025 04:38
Flask restfule representations example

В классе Resource из библиотеки flask_restful атрибут representations используется для определения форматов, в которых ресурс может возвращать данные. Это позволяет вам указать, как данные должны быть представлены в ответе в зависимости от заголовка Accept в запросе.

Вот пример, как можно использовать representations в классе Resource:

from flask import Flask, Response
from flask_restful import Api, Resource, marshal_with, fields
from flask_restful.representations.json import output_json
from typing import Any, Dict, Optional
@c80609a
c80609a / README.md
Created March 30, 2025 12:02 — forked from ihciah/README.md
V2ray with cloudflare websocket

Configure v2ray with cloudflare with docker and docker-compose

  • caddy-*: http server related files
  • v2ray-*: v2ray related files
  • forword-*: files to relay requests
@c80609a
c80609a / pgplaybook.yml
Created March 25, 2025 01:18 — forked from internetuser2008/pgplaybook.yml
custom Ansible Playbook to deploy PostgerSql or PostgreSql BDR + Pgbackrest + Pgbouncer
# Usage
# host supply IP
# -t(tags) run specific tasks ie. db=master, dbslave=slave1/2, promote=update slave to master, remove= remove host
# ansible-playbook pg.yml -e "host=192.169.99.2 -t db ##Build Master
# ansible-playbook pg.yml -e "host=192.168.99.3" -t dbslave ##Build Slave
# ansible-playbook pg.yml -e "host=192.168.99.3" -t promote ##Promoe slave to master
# ansible-playbook pg.yml -e "host=192.168.99.2" -t remove ##Remove node from cluster
# ansible-playbook /var/lib/pgsql/pg.yml -e "host=192.168.99.4" -s -t db --user=user1 --ask-sudo-pass ##Ubuntu
# Created Bimal Patel
---
@c80609a
c80609a / update_zapret.sh
Created March 5, 2025 16:48 — forked from kotsmotritnastul/update_zapret.sh
как обновить zapret одним скриптом
#!/bin/sh
unset latest_version_on_github
unset current_version_on_router
main()
{
find_out_what_os_we_work_in
find_out_what_version_is_here
find_out_what_version_is_on_github
if compare_version
then
@c80609a
c80609a / py.py
Created February 15, 2025 16:05
Скрипт капчевания двача by AI
import requests
from peewee import SqliteDatabase, Model, AutoField, TextField, IntegerField
import time
# Имя базы данных
db = SqliteDatabase("threads.db")
# Определение модели
class Post(Model):
id = AutoField()
post_num = IntegerField() # Автоинкрементный первичный ключ
@c80609a
c80609a / nginx_centos.md
Created December 28, 2024 04:58
установке nginx на сервер CentOS

Речение о установке nginx на сервер CentOS:

«Господа честные, буде желаете воздвигнуть слугу верного, именуемого nginx, на сервер свой, дабы он управлял трафиком и служил верой и правдой, послушайте речения моего.

  1. Подготовка царства (сервера):
    Прежде всего, удостоверьтесь, что царство ваше (сервер) обновлено и готово к деяниям великим. Изреките команду сию:
    sudo yum update -y