Skip to content

Instantly share code, notes, and snippets.

View Fivell's full-sized avatar
🏠
Working from home

Igor Fedoronchuk Fivell

🏠
Working from home
View GitHub Profile

Status

This extension was developed as part of the jsonapi module for Drupal.

Introduction

The JSON API specification is agnostic about how a server implements filtering strategies. In fact, the spec says:

Note: JSON API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

<?php
function get_tls_version($sslversion = null)
{
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "https://www.howsmyssl.com/a/check");
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
if ($sslversion !== null) {
curl_setopt($c, CURLOPT_SSLVERSION, $sslversion);
}
pool: number indicating size of connection pool (default 5)
checkout_timeout: number of seconds to block and wait for a connection before giving up and raising a timeout error (default 5 seconds).
reaping_frequency: frequency in seconds to periodically run the Reaper, which attempts to find and close dead connections, which can occur if a programmer forgets to close a connection at the end of a thread or a thread dies unexpectedly. (Default nil, which means don't run the Reaper).
dead_connection_timeout: number of seconds from last checkout after which the Reaper will consider a connection reapable. (default 5 seconds).
encoding: (Optional) Sets the client encoding by executing "SET NAMES <encoding>" after connection.
reconnect: Defaults to false (See MySQL documentation: dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html).
strict: Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: dev.mysql.com/doc/refman/5.0/en
@Fivell
Fivell / chat.rb
Created December 13, 2019 10:41 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@Fivell
Fivell / pg_application_name_patch.rb
Created December 12, 2018 15:57 — forked from vagmi/pg_application_name_patch.rb
Set the application name for a postgres connection in Rails 3
module ActiveRecord
module ApplicationName
def self.included(base)
unless base.respond_to? :establish_connection_with_application_name
base.extend ClassMethods
base.class_eval do
class << self
alias_method_chain :establish_connection, :application_name
end
end
@Fivell
Fivell / order.js
Created June 13, 2018 11:54 — forked from af23me/order.js
$.ajax({
type: 'POST',
url: "https://sandbox-api.didww.com/v3/orders",
data: JSON.stringify({
data: {
type: "orders",
attributes: {
allow_back_ordering: false,
items: [{
type: "did_order_items",
@Fivell
Fivell / mock_tcp_socket.rb
Created September 7, 2017 16:22 — forked from earlonrails/mock_tcp_socket.rb
Mock tcp socket for spec tests with ruby!!!
require 'socket'
require 'mocks'
TCP_NEW = TCPSocket.method(:new) unless defined? TCP_NEW
#
# Example:
# mock_tcp_next_request("<xml>junk</xml>")
#
class FakeTCPSocket
@Fivell
Fivell / curl.md
Created July 26, 2017 18:48 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@Fivell
Fivell / form.html
Created June 24, 2017 12:34 — forked from runspired/form.html
How to turn off password and email/username autocomplete.
<!--
<form autocomplete="off"> will turn off autocomplete for the form in most browsers
except for username/email/password fields
-->
<form autocomplete="off">
<!-- fake fields are a workaround for chrome/opera autofill getting the wrong fields -->
<input id="username" style="display:none" type="text" name="fakeusernameremembered">
<input id="password" style="display:none" type="password" name="fakepasswordremembered">
@Fivell
Fivell / description.markdown
Created January 24, 2017 22:34 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.