Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
RECIPIENT="your.email@address.here";
PREFIX="LOGIN ALERT!";
REMOTEIP=$(/bin/echo $SSH_CLIENT | /usr/bin/awk '{ print $1 }');
TIME=$(/bin/date +'%r, %D');
HOST=$(/bin/hostname -f);
if [[ "$REMOTEIP" == "" ]]; then
REMOTEIP='localhost';
fi
@SafeAF
SafeAF / .bashrc
Last active August 29, 2015 14:23 — forked from tommybutler/.bashrc
# put timestamps in my bash history
export HISTTIMEFORMAT='%F %T '
# don't put duplicate commands into the history
export HISTCONTROL=ignoredups
# record only the most recent duplicated command (see above)
export HISTCONTROL=ignoreboth
# don't record these commands in the history; who cares about ls?
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@SafeAF
SafeAF / rvm-usage.txt
Last active August 29, 2015 14:26
rvm advanced usage examples
$ \curl -sSL https://get.rvm.io | bash -s stable
$ echo "source ~/.profile" >> ~/.bash_profile
$ echo "gem: —no-document" >> ~/.gemrc
$ rvm autolibs enable
$ rvm install ruby
$ gem install rails
$ rvm use 2.2 --default
# Update your RVM to the latest statble version.
rvm get latest
# Update your RVM to the most recent version. (most bug fixes)
@SafeAF
SafeAF / redis_json_marshal_eval_benchmarks.rb
Last active August 29, 2015 14:26 — forked from shilov/redis_json_marshal_eval_benchmarks.rb
Ruby Redis benchmarks for JSON vs Marshal vs String and code examples
Redis Marshaling
If you have time consuming method in your app that you call frequently, chances are that you’d like to cache it. Redis is great key-value store that can be used for this purpose. However, redis only store string values. In order to store other kinds of objects, you’ll have to use marshaling.
There is a built-in ruby class called Marshal that does the job well. The only thing you have to do is to call Marshal.dump method and pass it an object. The exact opposite is the Marshal.load method.
I’ve created helper method for easier integration with Redis. Here is how it looks:
module RedisHelper
@SafeAF
SafeAF / redis-admin-tips.pro
Created July 30, 2015 20:42
redis pro stuff admin settings configs best practices
http://redis.io/topics/admin
Redis Administration
This page contains topics related to the administration of Redis instances. Every topic is self contained in form of a FAQ. New topics will be created in the future.
Redis setup hints
We suggest deploying Redis using the Linux operating system. Redis is also tested heavily on OS X, and tested from time to time on FreeBSD and OpenBSD systems. However Linux is where we do all the major stress testing, and where most production deployments are working.
Make sure to set the Linux kernel overcommit memory setting to 1. Add vm.overcommit_memory = 1 to /etc/sysctl.conf and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect immediately.
Make sure to disable Linux kernel feature transparent huge pages, it will affect greatly both memory usage and latency in a negative way. This is accomplished with the following command: echo never > sys/kernel/mm/transparent_hugepage/enabled.
Make sure to setup some swap in your syst
@SafeAF
SafeAF / key and value.rb
Created August 9, 2015 17:30
active support instrumentation
### start_processing.action_controller
| Key | Value |
| ------------- | --------------------------------------------------------- |
| `:controller` | The controller name |
| `:action` | The action |
| `:params` | Hash of request parameters without any filtered parameter |
| `:format` | html/js/json/xml etc |
| `:method` | HTTP request verb |
@SafeAF
SafeAF / example.erb
Last active August 29, 2015 14:27 — forked from jjulian/example.erb
Running Ruby under Apache like PHP, using cgi - http://stackoverflow.com/a/1901772/231245
<% header "Content-Type" => "text/html" %>
<h1>Let's run some ruby code: <%= rand %></h1>
@SafeAF
SafeAF / config.json
Last active September 1, 2015 13:24 — forked from anonymous/config.json
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@SafeAF
SafeAF / rb_c_xor_file_contents_extension.rb
Last active September 1, 2015 17:13 — forked from nruth/rb_c_xor_file_contents_extension.rb
RubyInline C experimentation
# run with Piece.xor_files 'output_filepath', ['infilepath1','infilepath2']
require 'inline'
Class Piece
inline do |builder|
builder.include '<stdlib.h>'
builder.include '<stdio.h>'
builder.c_singleton <<-C_CODE
/*
rb_input_paths_array should be a ruby array of strings,