Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
bogdanRada / add_intellij_launcer
Created October 6, 2022 13:05 — forked from rob-murray/add_intellij_launcer
Add Intellij launcher shortcut and icon for ubuntu
// create file:
sudo vim /usr/share/applications/intellij.desktop
// add the following
[Desktop Entry]
Version=13.0
Type=Application
Terminal=false
Icon[en_US]=/home/rob/.intellij-13/bin/idea.png
Name[en_US]=IntelliJ
@bogdanRada
bogdanRada / mysql2-gem-install.md
Created September 27, 2022 10:48 — forked from dteoh/mysql2-gem-install.md
Installing mysql2 gem

Installing mysql2 gem

This is always an annoying process, especially when you are setting up a new computer. I assume you are using macOS + homebrew. I also assume that you want to run an older version of MySQL (although the instructions should be adaptable).

Installing MySQL

$ brew install mysql@5.7 # change the version if needed
# Just a copy of https://stackoverflow.com/a/30724359/1825727
def from_hashstring(value)
json_string = value
.gsub(/([{,]\s*):([^>\s]+)\s*=>/, '\1"\2"=>') # Handle ruby symbols as keys
.gsub(/([{,]\s*)([0-9]+\.?[0-9]*)\s*=>/, '\1"\2"=>') # Handle numbers as keys
.gsub(/([{,]\s*)(".+?"|[0-9]+\.?[0-9]*)\s*=>\s*:([^,}\s]+\s*)/, '\1\2=>"\3"') # Handle symbols as values
.gsub(/([\[,]\s*):([^,\]\s]+)/, '\1"\2"') # Handle symbols in arrays
.gsub(/([{,]\s*)(".+?"|[0-9]+\.?[0-9]*)\s*=>/, '\1\2:') # Finally, convert => to :
JSON.parse(json_string)
ThinkingSphinx::Index.define(
:incident,
with: :active_record,
delta?: false,
delta_processor: ThinkingSphinx::Deltas.processor_for(ThinkingSphinx::Deltas::ResqueDelta)
) do
where "incidents.deleted = 0 AND accounts.status = 'enabled'"
set_property group_concat_max_len: 8192
indexes name, sortable: true
@bogdanRada
bogdanRada / mysql-large-db-import
Created August 27, 2022 16:17 — forked from molotovbliss/mysql-large-db-import
Importing Large DB faster MySQL Settings
Source: https://dba.stackexchange.com/questions/83125/mysql-any-way-to-import-a-huge-32-gb-sql-dump-faster
innodb_buffer_pool_size = 4G
innodb_log_buffer_size = 256M
innodb_log_file_size = 1G
innodb_write_io_threads = 16
innodb_flush_log_at_trx_commit = 0
Why these settings ?
innodb_buffer_pool_size will cache frequently read data
@bogdanRada
bogdanRada / mysql-faster-imports.sh
Created August 26, 2022 10:58 — forked from OZZlE/mysql-faster-imports.sh
Linux Bash Script to toggle faster mysql db imports
#!/usr/bin/env bash
# USAGE: mysqlOptimizeForImports <- before importing
# mysqlDefaultSettings <- to go back to normal
# Based on https://dba.stackexchange.com/questions/83125/mysql-any-way-to-import-a-huge-32-gb-sql-dump-faster/83385#83385
mysqlStateFile="$HOME/mysql.optimized.for.exports"
mysqlConfigLocation="/etc/mysql/my.cnf" # <-- change to the correct for your system, should be for global mysql settings
@bogdanRada
bogdanRada / 1-echo.js
Created April 6, 2022 20:57 — forked from willywongi/1-echo.js
Load a Worker from a different domain (CORS + tricks)
/*
You want to use webworkers, but you host all of your js files on a different domain than where
your app lives (es. app.example.com and js.example.com). Given that the static file served from
js.example.com are CORS ready (in that the response header includes Accept-origin: *), I thought
I could load a Worker from other domains. I was almost wrong, but at last I found a solution:
XHRing the worker source and create an inline worker. This is tested only on Firefox (latest).
*/
// This is an example webworker that is on js.example.com. It just echoes messages it receive.
self.onmessage = function(e) {
self.postMessage(e.data);
@bogdanRada
bogdanRada / 660-init-deb.sh
Created March 10, 2022 09:18
Linode script to register nginx after passenger isntall http://library.linode.com/assets/660-init-deb.sh
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
class RemovePaperclipColumnsFromModels < ActiveRecord::Migration[5.2]
def up
remove_column :model, :logo_content_type
remove_column :model, :logo_file_name
remove_column :model, :logo_file_size
remove_column :model, :logo_fingerprint
remove_column :model, :logo_updated_at
end
def down
@bogdanRada
bogdanRada / blob_observer.rb
Created February 25, 2022 11:07 — forked from mihaic195/blob_observer.rb
Blob observer
class BlobObserver < ActiveRecord::Observer
observe ActiveStorage::Blob
def after_save(blob)
blob.update_columns(storage_url: "https://s3-#{ENV['AWS_AS_S3_REGION']}.amazonaws.com/#{ENV['AWS_AS_S3_BUCKET']}/" + blob.key)
end
end