Skip to content

Instantly share code, notes, and snippets.

View bitkidd's full-sized avatar
🎯
Focusing

Chirill Ceban bitkidd

🎯
Focusing
View GitHub Profile
@bitkidd
bitkidd / generateToken.ts
Last active February 7, 2022 14:21
KeyCDN Secure Token
const domain = 'domain'
const secret = 'supersecret'
const expire = Math.round(Date.now() / 1000) + 120
const links: { original?: string } = {}
const path = `/${this.filetype}/${this.uid}.${this.fileext}`
const generateToken = ({ path, query = '' }: { path: string; query?: string }): string => {
// generate md5 token
const md5String = crypto
@bitkidd
bitkidd / example.js
Created July 12, 2019 14:22
Adonis.js v4 example exception handler
const BaseExceptionHandler = use('BaseExceptionHandler');
const Logger = use('Logger');
class ExceptionHandler extends BaseExceptionHandler {
async handle(error, { request, response, session, view }) {
const isJSON = request.accepts(['html', 'json']) === 'json';
const production = process.env.NODE_ENV === 'production';
if (error.code === 'E_INVALID_SESSION') {
session.flash({
@bitkidd
bitkidd / force-https-wp.stpl
Created March 29, 2019 12:55
VestaCP (Nginx + Php-fpm) force WordPress HTTPS
server {
listen %ip%:%web_ssl_port% http2;
server_name %domain_idn% %alias_idn%;
root %docroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
ssl on;
@bitkidd
bitkidd / facebook_key_hash.md
Last active February 12, 2019 16:42
Create key hash for Facebook

You can convert SHA-1 hash in hex format (as found in Play console) into base64 hash using next command:

echo 33:4E:48:84:19:50:3A:1F:63:A6:0F:F6:A1:C2:31:E5:01:38:55:2E | xxd -r -p | openssl base64

Output:

M05IhBlQOh9jpg/2ocIx5QE4VS4=
@bitkidd
bitkidd / uri.js
Last active January 18, 2018 21:01 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a')
parser.href = "http://example.com:3000/pathname/?search=test#hash"
parser.protocol // => "http:"
parser.host // => "example.com:3000"
parser.hostname // => "example.com"
parser.port // => "3000"
parser.pathname // => "/pathname/"
parser.hash // => "#hash"
parser.search // => "?search=test"
@bitkidd
bitkidd / script.sh
Created December 7, 2017 20:28 — forked from vielhuber/script.sh
PostgreSQL: Backup and restore pg_dump with password on command line #sql
# best practice: linux
nano ~/.pgpass
*:5432:*:username:password
chmod 0600 ~/.pgpass
# best practice: windows
edit %APPDATA%\postgresql\pgpass.conf
*:5432:*:username:password
# linux
@bitkidd
bitkidd / hooks.js
Last active August 14, 2017 22:04
Adonis assets compilation
'use strict'
const fs = require('fs')
const path = require('path')
const { hooks } = require('@adonisjs/ignitor')
hooks.after.providersRegistered(function () {
const View = use('Adonis/Src/View')
@bitkidd
bitkidd / .gitlab-ci.yml
Created July 27, 2017 15:23 — forked from comilab/.gitlab-ci.yml
GitLab.com + GitLab-CI + Shared runners + gulp + rsyncで自動デプロイ
image: node:latest
cache:
paths:
- node_modules/
before_script:
- apt-get update -y
- apt-get install rsync openssh-client -y
- npm install
@bitkidd
bitkidd / gopath-dirs.md
Last active July 20, 2017 21:39
Manage multiple GOPATH dirs with ease

The solution is simple. Just include the following snippet in your ~/.bashrc (or ~/.bash_profile) and reload your shell environment with source ~/.bashrc. This snippet will create a shell function that will override the builtin command cd with a customized one that scans the entered directory, and every other above, for a file named .gopath.

cd () {
    builtin cd "$@"
    cdir=$PWD
    while [ "$cdir" != "/" ]; do
        if [ -e "$cdir/.gopath" ]; then
 export GOPATH=$cdir #or GOPATH=$GOPATH:$cdir if you want to keep original $GOPATH
@bitkidd
bitkidd / logger.js
Last active December 1, 2017 13:44
adonis logger
'use strict'
const colors = use('colors/safe')
const Env = use('Env')
const colorStatus = function (status) {
let colorFn = status >= 500 ? colors.red // red
: status >= 400 ? colors.yellow // yellow
: status >= 300 ? colors.cyan // cyan