Skip to content

Instantly share code, notes, and snippets.

@SafeAF
SafeAF / _Rspec.md
Last active February 16, 2016 15:12 — forked from jhollinger/rspec_database_cleaner.rb
Optimal RSpec Database Cleaner config

RSPEC Cucumber etc and Testing in Ruby

@SafeAF
SafeAF / gist:331ab8b82f3293555501
Created January 15, 2016 23:13 — forked from jjb/gist:7389552
Ruby 2.1 memory configuration

This all applies to Ruby 2.1. In some cases a setting is not available in 2.0, this is noted. There is also a different with 1.9, 1.8, and REE --- these are not noted.

All the relevant code is in https://github.com/ruby/ruby/blob/trunk/gc.c

RUBY_HEAP_MIN_SLOTS

default: 10000

The number of heap slots to start out with. This should be set high enough so that your app has enough or almost enough memory after loading so that it doesn't have to allocate more memory on the first request (althogh this probably isn't such a big deal for most apps).

(todo: figure out how big a slot is. i think the answer can be infered from this code.)

@SafeAF
SafeAF / history.txt
Created January 15, 2016 02:59 — forked from unak/history.txt
The History of Ruby
* Only the releases of the stable versions are enumerated in principle. The releases of the unstable versions especially considered to be important are indicated as "not stable."
* The branches used as the source of each releases are specified, and the branching timing of them are also shown. BTW, before subversionizing of the repository, the term called "trunk" was not used, but this list uses it in order to avoid confusion.
* In order to show a historical backdrop, big conferences (RubyKaigi, RubyConf and Euruko) are also emurated. About the venues of such conferences, general English notations are adopted, in my hope.
* ruby_1_8_7 branch was recut from v1_8_7 tag after the 1.8.7 release becaouse of an accident.
* 1.2.1 release was canceled once, and the 2nd release called "repack" was performed. Although there were other examples similar to this, since the re-releases were performed during the same day, it does not write clearly in particular.
* Since 1.0 was released with the date in large quantities,
@SafeAF
SafeAF / cmd.sh
Created January 7, 2016 06:28 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@SafeAF
SafeAF / sa_embedded_mongoid_test.rb
Created December 31, 2015 05:12 — forked from nmk/sa_embedded_mongoid_test.rb
Mongoid standalone/embedded
require 'mongoid'
require 'minitest/autorun'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('basket_test')
end
class Basket
include Mongoid::Document
@SafeAF
SafeAF / Gemfile
Created November 30, 2015 05:53 — forked from ahaedike/Gemfile
source "https://rubygems.org"
gem 'eventmachine'
gem 'rubysl-stringio'
gem 'sinatra'
gem 'yajl-ruby', require: 'yajl'
gem 'thin'
gem 'em-websocket', :git=>'https://github.com/igrigorik/em-websocket.git'
@SafeAF
SafeAF / mongoose-encrypted-schematype-field.md
Created November 26, 2015 05:12 — forked from kljensen/mongoose-encrypted-schematype-field.md
Encrypt a text field in Mongoose MongoDB ORM

Encrypting text fields in Mongoose is easy using Node's built-in crypto module. You might want to do this if you're using MongoDB as a service (see the recent MongoHQ security breach); or, if you're storing OAuth tokens that could, in the wrong hands, screw with somebody's account on a 3rd party service. (Of course, you should never encrypt passwords: those should be hashed.)

Imagine you have a Mongoose model like that shown below, which is modified only slighly from the example on the MongooseJS homepage.

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');

var User = mongoose.model('User', {
 name: String,
@SafeAF
SafeAF / computeDistance.js
Created November 6, 2015 06:43 — forked from joseche/computeDistance.js
Compute the distance between two coordinates
function computeDistance(startCoords, destCoords) {
var startLatRads = degreesToRadians(startCoords.latitude);
var startLongRads = degreesToRadians(startCoords.longitude);
var destLatRads = degreesToRadians(destCoords.latitude);
var destLongRads = degreesToRadians(destCoords.longitude);
var Radius = 6371; // radius of the Earth in km
var distance =
Math.acos(Math.sin(startLatRads) * Math.sin(destLatRads) +
@SafeAF
SafeAF / gist:7d1f4eecdc06ca591d86
Created October 31, 2015 09:51 — forked from npassaro/gist:307a23f40287482a5275
How to use activerecord standalone
require 'active_record'
require 'sqlite3'
require 'logger'
ActiveRecord::Base.logger = Logger.new('debug.log')
ActiveRecord::Base.configurations = YAML::load(IO.read('database.yml'))
ActiveRecord::Base.establish_connection('development')
class Schema < ActiveRecord::Migration
def change
@SafeAF
SafeAF / sysctl.conf
Created October 22, 2015 01:35 — forked from rschmitty/sysctl.conf
ubuntu sysctl.conf settings
# changes from http://www.cyberciti.biz/faq/linux-kernel-etcsysctl-conf-security-hardening/
# Protect ICMP attacks
net.ipv4.icmp_echo_ignore_broadcasts = 1
# Turn on protection for bad icmp error messages
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Turn on syncookies for SYN flood attack protection
net.ipv4.tcp_syncookies = 1