Skip to content

Instantly share code, notes, and snippets.

@PragmaticEd
PragmaticEd / generate-ssh-key.sh
Created January 16, 2019 14:31 — forked from grenade/01-generate-ed25519-ssh-key.sh
Correct file permissions for ssh keys and config.
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/mozilla_rsa
@PragmaticEd
PragmaticEd / add.sh
Created January 16, 2019 11:26
Add sFTP user, limit home, and disable ssh
#!/bin/sh
USER="example"
PASS="example"
USER_ROOT="/var/www/example.lv"
# fix "Authentication token manipulation error" error:
# https://www.codevoila.com/post/26/fix-authentication-token-manipulation-error-when-changing-user-password-in-ubuntu
sudo mount -rw -o remount /
@PragmaticEd
PragmaticEd / fix-wordpress-permissions.sh
Created January 16, 2019 10:11 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@PragmaticEd
PragmaticEd / translation_presence_validator.rb
Created June 14, 2018 10:04
Globalize gem presence validation
# Usage in model:
#
# validates :title, translation_presence: true,
# validates :title, translation_presence: {message: ''}
#
class TranslationPresenceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.translations.each do |translation|
if translation[attribute].blank?
@PragmaticEd
PragmaticEd / translation_uniqueness_validator.rb
Last active June 14, 2018 12:26
Globalize gem uniqueness validation
# Usage in model:
#
# validates :title, translation_uniqueness: true # will assume it must be uniq across all languages
# validates :title, translation_uniqueness: {scope: :locale, message: ''}
#
class TranslationUniquenessValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.translations.each do |t|
@PragmaticEd
PragmaticEd / Capfile
Last active June 10, 2019 04:06
resque & scheduler in rails 5 #rails #resque #scheduler #jobs
require 'capistrano-resque'
@PragmaticEd
PragmaticEd / readme.md
Created May 27, 2018 09:20
diacritic & case insensitive search (Rails, MySql, MongoDB).md
Word.destroy_all
WordMongo.destroy_all

Word.create(name: 'xа́е́x')
WordMongo.create(name: 'xа́е́x')

search  = 'Xа́е́x'
pattern = /#{RegexpExtension.accent_insensitive_pattern Regexp.escape(search)}/
wm = WordMongo.where(name: pattern).first
@PragmaticEd
PragmaticEd / setup.md
Created May 17, 2018 11:32 — forked from kpheasey/setup.md
WSL, RVM & RubyMine; ubuntu on windows, bash on windows

Add inbound firewall rule for TCP 2222

  • Windows 10 has 2 new services, SSH Server Proxy and SSH Server Broker which will already be bound to port 22
  • Do not allow public connection on this rule, WSL is not proven safe

ConEmu

Add as cmd startup with bash.exe --login

Install the SSH server and some Rails essentials libraries in bash

sudo apt-get update && sudo apt-get upgrade -y
@PragmaticEd
PragmaticEd / store_stylesheet.rb
Created March 5, 2018 12:16 — forked from manuelmeurer/store_stylesheet.rb
How to compile custom Sass stylesheets during runtime
# lib/store_stylesheet.rb
class StoreStylesheet
def initialize(store)
@store = store
end
# The path of the compiled stylesheet, i.e. stores/id_timestamp.css
def stylesheet_file
filename = [
@store.id,