This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myexec | |
import ( | |
"bufio" | |
"bytes" | |
"context" | |
"fmt" | |
"io" | |
"os" | |
"os/exec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Respond from a controller with a Tempfile and have the middleware unlink and close it. | |
# | |
# Send a file as ActionController::DataStreaming.send_file() does. This however, handles a Tempfile as input | |
# and unlinks/closes once the middleware is done with it. You cannot use send_file() to stream a temporary | |
# file and also control when it is unlinked in your controller because the RACK middleware actually performs | |
# the sending of the file AFTER the controller has returned. Rack may even pass the filename to the web server | |
# and have it make the actual delivery (X-Sendfile). | |
# | |
# Largely ripped directly from ActionController::DataStreaming. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* NOTES: | |
1. On 64bit without stdlib.h included, atol and strtoul of >MAXINT | |
returns "18446744071562067968" which is ULONG_MAX-INT_MAX on 64bit | |
2. On 32bit | |
a. with or without stdlib, >MAXINT returns MAXINT for atol() | |
b. W/wo stdlib, strtoul does the correct conversion | |
SUGGESTIONS: | |
1. Build for 64bit but make sure stdlib.h is included | |
2. Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ipaddr' | |
class Ip < ActiveRecord::Base | |
attr_accessible :ip, :addr, :other_columns | |
# The 'addr' accessor is what you use to properly set/get the 'ip' column. | |
# This sets an instance variable to store the IPAddr class representing the | |
# ip column in either IPv4 or IPv6. | |
attr_accessor :addr | |
validates_presence_of :addr, :message => "Invalid or empty IP Address" |