Skip to content

Instantly share code, notes, and snippets.

View fiftin's full-sized avatar

Denis Gukov fiftin

View GitHub Profile
@fiftin
fiftin / add_background_to_spree_taxon.rb
Created September 14, 2015 04:11
Add image to model the example of Spree taxon model
class AddBackgroundToSpreeTaxons < ActiveRecord::Migration
def change
add_column :spree_taxons, :background_file_name, :string
add_column :spree_taxons, :background_content_type, :string
add_column :spree_taxons, :background_file_size, :integer
add_column :spree_taxons, :background_updated_at, :timestamp
end
end
@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 / 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 / count.sql
Last active November 22, 2016 07:25
Count the number of occurrences of a char in MySQL
UPDATE Entities SET depth = (LENGTH(path) - LENGTH(REPLACE(path, '/', ''))) + 2 WHERE path <> '';
@fiftin
fiftin / numDigits.js
Created December 27, 2016 03:17
Number of digits
function numDigits(x) {
return (Math.log10((x ^ (x >> 31)) - (x >> 31)) | 0) + 1;
}
@fiftin
fiftin / bestTick.js
Created December 27, 2016 03:19
Best ticks for Y axis
function bestTick(largest, mostticks) {
var minimum = largest / mostticks;
var magnitude = Math.pow(10, Math.floor(Math.log(minimum) / Math.log(10)));
var residual = minimum / magnitude;
var tick;
if (residual > 5) {
tick = 10 * magnitude;
} else if (residual > 2) {
tick = 5 * magnitude;
} else if (residual > 1) {
@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 / 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 / request.js
Created March 19, 2018 19:45
MyDataSpace request data
const data = Mydataspace.request('entities.get', {
root: 'MyDemoRoot',
path: 'data',
children: true,
filter: {
field1: 'test'
},
offset: 10,
limit: 200
});
@fiftin
fiftin / gifenc.sh
Created March 31, 2018 07:43
ffmpeg: script for convering to gif with high quality
#!/bin/sh
palette="/tmp/palette.png"
filters="fps=15,scale=1000:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2