Skip to content

Instantly share code, notes, and snippets.

@micperr
micperr / activeadmin_lang.rb
Last active November 14, 2019 16:11
ActiveAdmin language dropdown switch
config.namespace :admin do |admin|
admin.build_menu :utility_navigation do |menu|
menu.add :label => "Languages" do |lang|
lang.add :label => "English",:url => proc { url_for(:locale => 'en') }, id: 'i18n-en', :priority => 1
lang.add :label => "Polish",:url => proc { url_for(:locale => 'pl') }, id: 'i18n-pl', :priority => 2
end
menu.add id: 'current_user', label: -> { display_name(current_active_admin_user) }, if: :current_active_admin_user? do |usermenu|
usermenu.add label: 'Profile', url: -> { auto_url_for(current_active_admin_user) }
admin.add_logout_button_to_menu usermenu
@micperr
micperr / active_admin_extend.rb
Created November 14, 2019 11:16 — forked from fred/active_admin.rb
extend active admin to prettier boolean values
# It extends activeadmin to show pretty boolean values
#
# config/initializers/active_admin.rb
module ActiveAdmin
module Views
class TableFor
def bool_column(attribute)
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe }
end
@micperr
micperr / postgres-dump-restore.markdown
Last active October 15, 2019 09:13 — forked from jeremykendall/postgres-dump-restore.markdown
PostgreSQL: dump and restore (to db with different name and roles even)

Postgres Export and Import

Export

pg_dump -U [superuser] -Fc [dbname] > db.dump

Import

@micperr
micperr / uninstall_gems.sh
Created October 1, 2019 15:50 — forked from IanVaughan/uninstall_gems.sh
Uninstall all rbenv gems
#!/usr/bin/env bash
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
@micperr
micperr / motd.sh
Created August 7, 2019 12:41
MOTD (Message of the day) screen
#!/bin/bash
#Script to update motd with relevant information.
#Define output file
motd="/etc/motd"
# Collect information
HOSTNAME=`uname -n`
KERNEL=`uname -r`
CPU=`awk -F '[ :][ :]+' '/^model name/ { print $2; exit; }' /proc/cpuinfo`
@micperr
micperr / Makefile
Created April 26, 2019 07:39
Example of a detailed Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@micperr
micperr / UuidIdTrait.php
Created April 10, 2019 12:37
UUID & Auto Increment IDs trait
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\UuidInterface;
trait EntityIdTrait
{
/**
@micperr
micperr / docker-compose.yml
Created March 26, 2019 11:30 — forked from seanhandley/docker-compose.yml
How To Set Up Docker For Mac with Native NFS
version: '2'
services:
api:
volumes:
- "nfsmount:${CONTAINER_DIR}"
volumes:
nfsmount:
driver: local
driver_opts:
@micperr
micperr / arch_install.sh
Last active January 30, 2019 23:50
Arch Linux installation step by step commands (HP Spectre x360)
# Check network interface name
iwconfig
# Start and stop interface
ip link set {interface} up
ip link set {interface} down
# Search the available WiFi networks
iwlist interface scan | less
@micperr
micperr / postgre_triggers.sql
Created November 23, 2018 12:49
postgresql disable/enable all the triggers (foreign key checks etc)
DISABLE
SET session_replication_role = replica;
ENABLE
SET session_replication_role = DEFAULT;