Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile

Generated private key

openssl genrsa -out server.key 2048

To generate a certificate

openssl req -new -x509 -key server.key -out server.pem -days 3650

https

@openmailbox
openmailbox / my_server.rb
Last active July 27, 2018 03:57
Introductory Rack-compliant web server
require 'socket'
require 'rack'
require 'sinatra'
# Simple, rack-compliant web server
class MyServer
STATUS_CODES = {
200 => 'OK',
500 => 'Internal Server Error'
}
@janko
janko / 01-activerecord.rb
Created May 27, 2015 22:50
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
require "active_record"
ActiveRecord::Base.establish_connection('postgres:///testing')
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.class_eval do
create_table :played_quizzes, force: true do |t|
t.integer :player_ids, array: true
t.json :quiz_snapshot
end
class AgencyVisitPolicy
def initialize(user)
@user = user
end
def to_proc
Proc.new { |visit| visit.agency_id.in?([@user.agency_id, nil]) }
end
end
@fidothe
fidothe / gist:39d4ef9b8d84f8ddde77
Created March 18, 2015 09:14
Use PG JSON datatype with Lotus::Model (hacky hacky)
require 'lotus/model'
require 'json'
module Lotus::Model::Mapping::Coercions
def self.JSON(arg)
return nil if arg.nil?
case arg
when String
JSON.parse(arg)
else
@angeloashmore
angeloashmore / repository_timestamps.rb
Created February 20, 2015 20:38
Lotus::Model timestamps handling using an entity's @created_at and @updated_at via its Repository.
module Lotus
module Repository
# Timestamps handling using an entity's @created_at and @updated_at.
#
# @since 0.2.4
module Timestamps
# Override existing public API into hosting class to support @created_at
# and @updated_at using Ruby implementations (database agnostic).
#
# @since 0.2.4
@denji
denji / golang-tls.md
Last active April 17, 2025 21:33 — forked from spikebike/client.go
Simple Golang HTTPS/TLS Examples
Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
@filewalkwithme
filewalkwithme / main.go
Created February 7, 2015 21:50
Listening multiple ports on golang http servers
package main
import (
"net/http"
)
func main() {
finish := make(chan bool)
server8001 := http.NewServeMux()
@raggi
raggi / rack_sse.ru
Last active April 17, 2025 20:24
Rack SSE Example
# rack_sse.ru
#
# An example of basic real-time, single-room broadcast chat using Server Sent
# Events in plain old Rack. This example does NOT use hijack, or the async
# hacks, it just relies on a well implemented threaded Rack server (at time of
# writing this will therefore only work with puma!). Other servers should be
# fixed to support this, as it is pretty critical to how Rack *should* work on
# most servers. The only spec-acceptable failure in this case is not flushing
# the content stream on each yield (for which the rack spec has no workaround
# today).
@anthonyjsmith
anthonyjsmith / gist:53fccd30ee0873b06c8b
Created November 25, 2014 16:39
Non-expiring flash
# Visit:
# /main/set_flash
# /main/show_no_flash (as many times as you like)
# /main/show_flash ... and it shows the flash message
# (Rails 4.1.8, Ruby 2.1.1)
# app/controllers/main_controller.rb
class MainController < ApplicationController
def show_flash
render inline: flash[:notice] || "Flash is blank!"