Skip to content

Instantly share code, notes, and snippets.

View dachinat's full-sized avatar
💭
I may be slow to respond.

Dachi Natsvlishvili dachinat

💭
I may be slow to respond.
View GitHub Profile
@dachinat
dachinat / server.go
Created November 25, 2023 18:23 — forked from fwoodruff/server.go
QUIC Server
package main
import (
"crypto/tls"
"log"
"github.com/quic-go/quic-go"
"golang.org/x/net/context"
)
@dachinat
dachinat / client.go
Created November 25, 2023 18:23 — forked from fwoodruff/client.go
QUIC Client
package main
import (
"bytes"
"context"
"crypto/tls"
"log"
"net/http"
"time"
@dachinat
dachinat / InvoiceItem.rb
Created December 3, 2021 17:09
InvoiceItem model from one of my projects
class InvoiceItem < ApplicationRecord
# Constants
# Includes
# include AccountScope
include AASM
aasm column: "status", requires_lock: true do
state :pending, initial: true
state :closed
@dachinat
dachinat / Invoice.rb
Created December 3, 2021 17:07
Invoice model from one of my projects
class Invoice < ApplicationRecord
# Constants
# Includes
# include AccountScope
include AASM
aasm column: "status", requires_lock: true do
state :pending, initial: true
state :final, :paid
@dachinat
dachinat / messages_controller.rb
Created December 3, 2021 17:05
Messages Controller from one of my projects
class MessagesController < ApplicationController
before_action :authenticate_user!, except: %i[shared download_attachment download_eml raw_iframe view_attachment]
before_action :set_message, only: %i[show read download_attachment download_eml raw_iframe view_attachment destroy
share unshare], if: -> { params[:id] }
before_action :set_shared_message, only: %i[show download_attachment download_eml raw_iframe view_attachment shared],
if: -> { params[:token] }
def show
import React, {useState, useEffect} from 'react';
export default () => {
const [input, setInput] = useState([]);
useEffect(() => {
addInput();
}, []);
const addInput = () => {
@dachinat
dachinat / opendiff.md
Created November 13, 2018 23:34
opendiff with git on macOS single command

Was tested with git version 2.14.1

git config --global alias.opendiff 'difftool --no-prompt --tool opendiff --dir-diff'

and anytime after

git opendiff
@dachinat
dachinat / ufw_allow_countries.sh
Last active March 15, 2024 13:56
Allow certain countries only using UFW (Tested on CentOS 7, Ubuntu 16.04, Ubuntu 18.04)
#!/bin/bash
#title :ufw_allow_countries.sh
#author :JSC Novabyte (novabyte.co)
#date :20/10/2018
#version :0.0.1
#notes :Use root privileges
#usage :$sh ufw_allow_countries.sh
#license :https://opensource.org/licenses/MIT
@dachinat
dachinat / geocoder_test_locally.rb
Created November 17, 2017 20:04
Test geocoder when ip is 127.0.0.1
# config/geocoder.rb
module Geocoder
module Request
def location
@location ||= begin
Geocoder.search(IpAddress.new('190.12.48.158')).first
end
@location
end
@dachinat
dachinat / local_forms.js
Last active November 6, 2017 15:53
Localize (customize) form errors native to browsers. (jQuery Plugin)
/**
* Local forms jQuery plugin.
* Author: Dachi Natsvlishvili
*/
(function($) {
$.fn.local_forms = function(options) {
var handle = function(key, e) {
if (!e.validity.valid) {
$.each(options[key], function(key, value) {
if (e.validity[key]) {