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
def verified_request? | |
!protect_against_forgery? || request.get? || request.head? || | |
form_authenticity_token == params[request_forgery_protection_token] || | |
form_authenticity_token == request.headers['X-CSRF-Token'] | |
end |
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
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
end | |
def protect_from_forgery(options = {}) | |
self.request_forgery_protection_token ||= :authenticity_token | |
prepend_before_action :verify_authenticity_token, options | |
end | |
def verify_authenticity_token |
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
class ApplicationController < ActionController::Base | |
# Prevent CSRF attacks by raising an exception. | |
# For APIs, you may want to use :null_session instead. | |
protect_from_forgery with: :exception | |
end | |
def protect_from_forgery(options = {}) | |
self.forgery_protection_strategy = protection_method_class(options[:with] || :null_session) | |
self.request_forgery_protection_token ||= :authenticity_token | |
prepend_before_action :verify_authenticity_token, options |
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
class Exception | |
def initialize(controller) | |
@controller = controller | |
end | |
def handle_unverified_request | |
raise ActionController::InvalidAuthenticityToken | |
end | |
end |
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
==> day5_nethttp1.rb <== | |
# nethttp1.rb | |
require 'net/http' | |
url = URI.parse('http://ruby-metaprogramming.rubylearning.com/html/ruby_metaprogramming_1.html') | |
Net::HTTP.start(url.host, url.port) do |http| | |
req = Net::HTTP::Get.new(url.path) | |
puts http.request(req).body.split(/\W+/).count('the') | |
end |
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
// MOve to the directory containing the video files. | |
// Audio Files will be create with same name as the originalfile with ".mp4" appended to it. | |
// Generated content is stored into Audio directory under the current directory. | |
for file in *.*; do vlc -I dummy --no-sout-video --sout "#std{access=file,mux=raw,dst=output}" "$file" vlc://quit; mv output Audio/"$file".mp4; done |
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
//Simple CSV reader | |
package main | |
import ( | |
"encoding/csv" //Package csv reads and writes comma-separated values (CSV) files. | |
"fmt" //Package fmt implements formatted I/O with functions analogous to C's printf and scanf. | |
"io" //Package io provides basic interfaces to I/O primitives. | |
"os" //Package os provides a platform-independent interface to operating system functionality. | |
) |
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 5.
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
record1a, record1b, records1c | |
record2a, record2b, records2c | |
#This is a comment: DO NOT PROCESS | |
record3a, record3b, records3c | |
record4a", record4b, records4c | |
record5a, record5b, records5c |
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
> tempfile = Tempfile.new(["temp", "text"]) | |
=> #<Tempfile:/tmp/temp20141109-10110-2pjq04text> | |
> tempfile.write("sample tempfile.") | |
=> 16 | |
> tempfile.rewind | |
=> 0 | |
> tempfile.read | |
=> "sample tempfile." | |
> tempfile.close | |
=> nil |
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
> tempfile = Tempfile.new(["temp", "text"]) | |
=> #<Tempfile:/tmp/temp20141109-10110-2pjq04text> | |
> tempfile.write("sample tempfile.") | |
=> 16 | |
> tempfile.rewind | |
=> 0 | |
> tempfile.read | |
=> "sample tempfile." | |
> tempfile.close | |
=> nil |
OlderNewer