Skip to content

Instantly share code, notes, and snippets.

View fiftin's full-sized avatar

Denis Gukov fiftin

View GitHub Profile
@fiftin
fiftin / wsl.md
Created October 8, 2022 12:53 — forked from alyleite/wsl.md
Failed to connect to bus: Host is down - WSL 2

» sudo systemctl daemon-reload

System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

just try:

sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig

sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target

@fiftin
fiftin / sendmail_setup.md
Created October 2, 2022 18:41 — forked from kany/sendmail_setup.md
Setup SENDMAIL on Mac OSX Yosemite
@fiftin
fiftin / mysql-docker.sh
Created September 19, 2022 10:35 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@fiftin
fiftin / download-file.js
Created March 29, 2020 14:34 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
add_filter('upload_dir', 'cdn_upload_url');
function cdn_upload_url($args)
{
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
$is_id_user = ($current_user_id > 0) ? true : false;
switch($is_id_user)
{
case true:
$admin_users = array('administrator', 'editor', 'author'); //Add roles that you don't want to CDN swap
@fiftin
fiftin / delay.js
Created October 2, 2017 20:24 — forked from daliborgogic/delay.js
Node.js Async/Await delay
'use strict'
const timeout = ms => new Promise(res => setTimeout(res, ms))
function convinceMe (convince) {
let unixTime = Math.round(+new Date() / 1000)
console.log(`Delay ${convince} at ${unixTime}`)
}
async function delay () {
@fiftin
fiftin / mongodb-s3-backup.sh
Created August 21, 2017 14:58 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@fiftin
fiftin / Convert PostgreSQL to SQLite
Created October 5, 2015 07:04
Convert PostgreSQL to SQLite
1. Dump the data only sql to file
$ pg_dump --data-only --inserts YOUR_DB_NAME > dump.sql
2. scp to local
3. Remove the SET statements at the top
such as:
SET statement_timeout = 0;
SET client_encoding = 'SQL_ASCII';
4. Remove the setval sequence queries
@fiftin
fiftin / psql2sqlite.sed
Last active October 5, 2015 08:27 — forked from HGebhardt/psql2sqlite.sed
Convert PostgreSQL data to SQLite
#! /bin/sed -f
# add begin transaction
1s/^SET .*$/END;\nBEGIN;\n/
1s/^-- .*$/END;\nBEGIN;\n/
1s/^/BEGIN;\n/
# remove configuration settings
/^SET /d
@fiftin
fiftin / 0_example.rb
Last active September 13, 2015 18:44 — forked from radar/0_example.rb
Order.class_eval do
checkout_flow do
go_to_state :address
go_to_state :delivery
go_to_state :payment, :if => lambda { payment_required? }
go_to_state :confirm, :if => lambda { confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
end