Skip to content

Instantly share code, notes, and snippets.

def scan_for(matcher, text)
scanner = StringScanner.new(text)
last_byte, last_char = 0, 0
while scanner.scan_until(matcher)
byte = scanner.pos - scanner.matched.length
char = last_char + text[last_byte..byte].unpack('U*').length - 1
length = scanner.matched.unpack('U*').length
last_byte, last_char = byte, char
# Do something with the "char" offset and "length"...
end
<script type="text/javascript">
window.RAILS_ENV = '<%= RAILS_ENV %>';
window.SERVER_ROOT = '<%= DC_CONFIG["server_root"] %>';
<% if @current_account %>
dc.app.organization = <%= @current_organization.to_json %>;
dc.app.accountId = <%= @current_account.id %>;
Accounts.add(new dc.model.Account(<%= @current_account.to_json %>));
Labels.populate(<%= @current_account.labels.alphabetical.to_json %>);
Bookmarks.populate(<%= @current_account.bookmarks.alphabetical.to_json %>);
SavedSearches.populate(<%= @current_account.saved_searches.alphabetical.to_json %>);
// When the next click or keypress happens, anywhere on the screen, hide the
// element. 'clickable' makes the element and its contents clickable without
// hiding. The 'onHide' callback runs when the hide fires, and has a chance
// to cancel it.
autohide : function(options) {
var me = this;
options = _.extend({clickable : null, onHide : null}, options || {});
me._autoignore = true;
setTimeout(function(){ delete me._autoignore; }, 0);
/////////////////////////////////////////////////////////////////////////////
// The public DocumentViewer API. Available for other scripts to access:
/////////////////////////////////////////////////////////////////////////////
(function(){
DV.api = {
// Return the current page of the document.
currentPage : function() {
return DV.controller.models.document.currentPage();
# Convenience method for responding with JSON. Sets the content type,
# serializes, and allows empty responses. If json'ing an ActiveRecord object,
# and the object has errors on it, a 409 Conflict will be returned with a
# list of error messages.
def json(obj, status=200)
obj = {} if obj.nil?
if obj.respond_to?(:errors) && obj.errors.any?
obj = {'errors' => obj.errors.full_messages}
status = 409
end
state 67
5) Expressions : Expressions _ Terminator Expression
6) Expressions : Expressions _ Terminator
7) Expressions : Terminator Expressions _
"\n" shift, and go to state 23
"\n" [reduce using rule 7 (Expressions)]
";" shift, and go to state 29
";" [reduce using rule 7 (Expressions)]
# Any list of expressions or method body, seperated by line breaks or semis.
Expressions:
Expression { result = Nodes.new(val) }
| Expressions Terminator Expression { result = val[0] << val[2] }
| Expressions Terminator { result = val[0] }
| Terminator Expressions { result = val[1] }
;
redraw : function(stopResetOfPosition){
// console.log('forcing')
this.pages['p0'].draw({ force: true });
this.pages['p1'].draw({ force: true });
this.pages['p2'].draw({ force: true });
if(this.application.state != 'InitialLoad' && !stopResetOfPosition){
this.application.helpers.jumpTo(this.application.models.document.currentIndex());
}
},
/////////////////////////////////////////////////////////////////////////////
// The public DocumentViewer API. Available for other scripts to access:
/////////////////////////////////////////////////////////////////////////////
// Return the total number of pages in the document.
DV.controller.numberOfPages = function() {
return this.models.document.totalPages;
};
// Change the documents' sections, re-rendering the navigation. "sections"
<div class="title"><%= title %></div>
<% if (text) { %>
<div class="text"><%= text %></div>
<% } %>
<% if( mode == 'prompt' || mode == 'short_prompt') { %>
<div class="<%= mode %>">
<% if( mode == 'prompt') { %>
<textarea class="content"></textarea>
<% } else { %>
<input class="content" type="text" value="" />