Skip to content

Instantly share code, notes, and snippets.

@SafeAF
SafeAF / deploy.rb
Created August 20, 2016 23:22 — forked from ahawkins/deploy.rb
Deploy script for Heroku apps
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
@SafeAF
SafeAF / api_controller.rb
Created August 20, 2016 23:16 — forked from ahawkins/api_controller.rb
Basic API style controller for Rails
# A Basic API Controller for Rails
# Handles authentication via Headers, params, and HTTP Auth
# Automatically makes all requests JSON format
#
# Written for production code
# Made public for: http://broadcastingadam.com/2012/03/state_of_rails_apis
#
# Enjoy!
class ApiController < ApplicationController
@SafeAF
SafeAF / passive-ip-geo-location.js
Created July 2, 2016 06:15
js passive geo locator ui in
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body { margin: 1em; }
#map { height: 500px; }
#intro { font-size: 14px; font-family: arial; max-width: 500px; margin: 1em auto 1em auto; text-align: justify; }
</style>
@SafeAF
SafeAF / node_debian_init.sh
Created June 29, 2016 10:32 — forked from sebseb7/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#!/bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@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

xport RUBY_GC_HEAP_INIT_SLOTS=600000
export RUBY_GC_HEAP_FREE_SLOTS=600000
export RUBY_GC_HEAP_GROWTH_FACTOR=1.25
export RUBY_GC_HEAP_GROWTH_MAX_SLOTS=300000
or this
# Boost Ruby
export RUBY_GC_HEAP_INIT_SLOTS=1000000 # 1M
export RUBY_GC_HEAP_FREE_SLOTS=500000 # 0.5M
export RUBY_GC_HEAP_GROWTH_FACTOR=1.1
@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