Skip to content

Instantly share code, notes, and snippets.

View sergeyklay's full-sized avatar
🇺🇦

Serghei Iakovlev sergeyklay

🇺🇦
View GitHub Profile
@sergeyklay
sergeyklay / install.sh
Last active October 18, 2020 11:03
Install Nginx with Nchan
#!/usr/bin/env bash
# Works fine on Ubuntu 14.0.4 LTS
NGINX_VERSION="1.9.9"
NCHAN_VERSION="0.97"
HEADERS_MORE_VERSION="0.29"
DEV_KIT_VERSION="0.2.19"
ECHO_VERSION="0.58"
FANCY_INDEX_VERSION="0.3.5"
@sergeyklay
sergeyklay / get_phalcon_events.sh
Last active September 15, 2020 12:26
Phalcon : Get list of all events from source
$ pwd
/home/klay/projects/c/cphalcon
$ git branch
2.0.0
* 2.0.x
master
$ php --ri phalcon | grep 'Version =>'
@sergeyklay
sergeyklay / rpn.kt
Last active May 30, 2020 09:17
Reverse Polish Notation
import java.util.Stack
import java.lang.Long.parseLong
fun String.isNumeric(): Boolean {
return try {
parseLong(this)
true
} catch (e: NumberFormatException) {
false
}

Here's how to test whether a parameter is unset, or empty ("Null") or set with a value:

+--------------------+----------------------+-----------------+-----------------+
|                    |       parameter      |     parameter   |    parameter    |
|                    |   Set and Not Null   |   Set But Null  |      Unset      |
+--------------------+----------------------+-----------------+-----------------+
| ${parameter:-word} | substitute parameter | substitute word | substitute word |
| ${parameter-word}  | substitute parameter | substitute null | substitute word |
| ${parameter:=word} | substitute parameter | assign word     | assign word     |
| ${parameter=word}  | substitute parameter | substitute null | assign word     |
@sergeyklay
sergeyklay / .dir-local.el
Last active March 29, 2020 16:21
.dir-local.el for PHP-extension
;;; Directory Local Variables
;; For more information see (info "(emacs) Directory Variables")
((nil . ((indent-tabs-mode . t)
(fill-column . 80)))
(c-mode . ((c-file-style . "k&r")
(tab-width . 4)
(c-basic-offset . 4)
(flycheck-checker . c/c++-gcc)
(flycheck-disabled-checkers c/c++-clang)
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@sergeyklay
sergeyklay / template.service
Created July 14, 2019 11:16 — forked from chrj/template.service
Sample service unit file for systemd
[Unit]
Description=My service
[Service]
ExecStart=/usr/local/bin/my-service \
-argument value \
-otherargument othervalue
# Setuid/Setgid
User=nobody
@sergeyklay
sergeyklay / version-compare.clj
Created June 22, 2019 10:58
Simple version compare using clojure
(defn- normalize-verison
[version]
(let [[x y z] (map read-string (clojure.string/split version #"\."))
z (or z 0)]
(+ (* x 10000) (* y 100) z)))
(defn version-compare
[a b]
(let [left (normalize-verison a)
right (normalize-verison b)]
@sergeyklay
sergeyklay / telnet-imap
Last active May 30, 2019 07:24
Playing with Gmail via Telnet
$ telnet-ssl -z ssl imap.gmail.com 993
Trying 173.194.222.109...
Connected to gmail-imap.l.google.com.
Escape character is '^]'.
* OK Gimap ready for requests from 193.201.216.169 z8mb75199760ljk
a1 LOGIN xxxxxxxx@gmail.com my-password-here
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584
a1 OK xxxxxxxx@gmail.com authenticated (Success)
a2 LIST "" "*"
* LIST (\HasNoChildren) "/" "INBOX"
@sergeyklay
sergeyklay / get-the-weather-data-for-my-city.el
Last active April 2, 2019 10:14
get the weather data for my city
(require 'json)
(defvar owm/base-api-url "api.openweathermap.org")
(defvar owm/base-api-ver 2.5)
(defvar owm/api-key "PUT_API_KEY_HERE")
(defvar owm/default-scheme "https")
(defun owm/build-url (appid lat lon lang units)
(let* ((local (format "data/%s/weather" owm/base-api-ver))