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
# find methods of an Array that have ! equivalents: e.g. map (Note: the method /methods/ returns an Array of /Symbol/s) | |
[].methods.delete_if{|x| [].methods.index((x.to_s+"!").to_sym) == nil} | |
# => [:reverse, :rotate, :sort, :collect, :map, :select, :reject, :slice, :uniq, :compact, :flatten, :shuffle, :sort_by] | |
# find methods of a String that have ! equivalents: e.g. sub | |
"".methods.delete_if{|x| "".methods.index((x.to_s+"!").to_sym) == nil} | |
#=> [:succ, :next, :upcase, :downcase, :capitalize, :swapcase, :reverse, :sub, :gsub, :chop, :chomp, :strip, :lstrip, :rstrip, :tr, :tr_s, :delete, :squeeze, :slice, :encode] |
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/env ruby | |
class Foo | |
# This is m1. It gets documented correctly. | |
# @param [Integer] id an integer representing unique ID | |
# @param [String] name string representing the name | |
# @see #m2 | |
def m1(id, name) | |
end |
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
source 'https://rubygems.org' | |
# details omitted ... | |
#1 | |
gem 'rdoc_rest', :git => 'git://github.com/kedarmhaswade/rdoc_rest.git' | |
#2 | |
#gem 'rdoc_rest' | |
# To use ActiveModel has_secure_password | |
# gem 'bcrypt-ruby', '~> 3.0.0' | |
# To use Jbuilder templates for JSON |
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
# Demo::Rack::ApiAccess is a rack middleware and implements the rack interface. | |
# Its purpose is to validate the API access. In essence, it "logs in" the user for which | |
# the current request has an access_token. | |
require 'oauth2/provider/models/active_record/access_token' | |
module Demo::Rack | |
class ApiAccess | |
def initialize(app) | |
@app = app | |
end |
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
# put this in an initializer | |
# a Rails 3.2 addendum for: http://accuser.cc/posts/1-rails-3-0-exception-handling | |
class MyShowExceptions | |
def initialize() | |
@@rescue_responses = Hash.new(:internal_server_error) | |
@@rescue_responses.update({ | |
'ActionController::RoutingError' => :not_found, | |
'AbstractController::ActionNotFound' => :not_found, | |
'ActiveRecord::RecordNotFound' => :not_found, |
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
MyApp::Application.config.middleware.insert_before ActionDispatch::ShowExceptions, ExceptionNotifier, | |
:sender_address => "[email protected]", | |
:exception_recipients => "[email protected]", | |
MyApp::Application.config.middleware.insert_after ExceptionNotifier, ActionDispatch::ShowExceptions | |
require 'action_dispatch/middleware/show_exceptions' | |
module ActionDispatch | |
class ShowExceptions | |
private | |
def render_exception_with_template(env, exception) |
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
rm -f | |
(in /home/kedar/.rvm/src/rbx-head) | |
** Invoke install (first_time) | |
** Invoke build:build (first_time) | |
** Invoke build:llvm (first_time) | |
** Execute build:llvm | |
** Invoke vm/vm (first_time) | |
** Invoke vm/gen/revision.h (first_time) | |
** Execute vm/gen/revision.h | |
/home/kedar/.rvm/rubies/ruby-1.9.2-head/bin/ruby vm/codegen/config_vars.rb vm/gen/config_variables.h |
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 j = jQuery.noConflict(); | |
j("body").append("<%= escape_javascript(render :partial => 'problems/problem_gallery_carousel')%>"); | |
j("#show-problem-gallery-link").unbind(); | |
j("#show-problem-gallery-link").attr("data-remote", "false"); //no Ajax anymore | |
j("#show-problem-gallery-link").click(function() { //attach a JS-only event handler | |
j("#problem-gallery-carousel").carousel({interval: false}); | |
j("#problem-gallery-modal").modal('show'); | |
}); |
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
/* Can we truncate a file from outside? */ | |
#include <stdio.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <errno.h> | |
int main(int argc, char** argv) { | |
/* opens the given argv[1] and writes a statement to it every 5 seconds */ | |
int fd; |
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
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.atomic.AtomicLong; | |
public class DiningPhilosophers { | |
volatile static boolean done; | |
final private Integer[] chopsticks; | |
public DiningPhilosophers(int n) { | |
chopsticks = new Integer[n]; | |
for (int i = 0 ; i < n ; i++) |
OlderNewer