Skip to content

Instantly share code, notes, and snippets.

View spidergears's full-sized avatar

Deepak Singh spidergears

View GitHub Profile
//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.
record1a, record1b, records1c
record2a, record2b, records2c
#This is a comment: DO NOT PROCESS
record3a, record3b, records3c
record4a", record4b, records4c
record5a, record5b, records5c
@spidergears
spidergears / tempfile.rb
Last active August 29, 2015 14:09
Ruby Tempfile class
> 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
> 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
@spidergears
spidergears / bar_chart.html
Created February 1, 2015 19:13
d3.js Demo1
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.chart div {
font: 10px sans-serif;
background-color: blue;
text-align: right;
padding: 3px;
margin: 1px;
@spidergears
spidergears / manifest.json
Last active August 29, 2015 14:17
chrome_extension_manifest
{
"name": "ChromeToPocket",
"short_name": "ChromeToPocket",
"description": "Import your chrome bookamrks to Pocket",
"version": "0.1",
"manifest_version": 2,
"browser_action": {
"default_icon": "import.png",
"default_popup": "popup.html"
},
@spidergears
spidergears / popup.html
Created March 27, 2015 06:07
chrome_extension_popup
<html>
<head>
<title>ChromeToPocket</title>
<script src="import.js"></script>
<style>
* {
margin: 5;
padding: 5;
}
html, body {
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
class Exception
def initialize(controller)
@controller = controller
end
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
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