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 / 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 / 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,
@SafeAF
SafeAF / authentication_with_bcrypt_in_rails_4.md
Last active September 4, 2015 01:13 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@SafeAF
SafeAF / us-ips.rb
Last active September 7, 2015 08:28
iptables rule generator to allow US-based IP addresses
require 'csv'
require 'ipaddr'
last = nil
CSV.foreach("us.csv") do |row|
next if row.empty?
from = IPAddr.new(row[0])
to = IPAddr.new(row[1])
mask = from.to_i ^ to.to_i
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby