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 Ninja{private final String test="This is just a test String";private Ninja(){}public String getTest(){return test;}} |
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
Bart: Remember when Tom had you in that headlock and you screamed, "I'm a hemophiliac!," and when he let you go, you kicked him in the back? | |
Homer: Yeah. | |
Bart: Will you teach me how to do that? | |
Homer: Sure, boy. First, you gotta shriek like a woman and keep sobbing until he turns away in disgust. That's when it's time to kick some back. And then when he's lying down on the ground,... | |
Bart: Yeah. | |
Homer: Kick him in the ribs. | |
Bart: Yeah. | |
Homer: Step on his neck. | |
Bart: Yeah. | |
Homer: And run like hell. |
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
# My solution to: https://gist.github.com/280aa4797a580fb8ae75 | |
class Polynomial | |
class Term | |
attr_reader :power, :coefficient | |
def initialize(power, coefficient) | |
@power = power | |
@coefficient = coefficient | |
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
# Given 50/50 chance of true. | |
def equal_prob | |
return (rand < 0.5) | |
end | |
# 0.314159.. chance of true | |
def biased_prob | |
if equal_prob | |
pivot = 2 * Math::PI / 10 | |
return (rand < pivot) |
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
public class ThreadNinja { | |
private int rank; | |
public synchronized void fight(ThreadNinja enemy) { | |
if (!enemy.canDefend(this)) { | |
rank++; | |
} | |
} | |
public synchronized boolean canDefend(ThreadNinja enemy) { |
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
answer | |
options = { :choices => 'jokes, sports', | |
:repeat => 3 } | |
result = ask 'For jokes, just say jokes. For sports, say sports.', options | |
if result.name == 'choice' | |
case result.value | |
when 'jokes' |
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 luhn?(ccn) | |
ccn = ccn.split(//).map! {|x| x.to_i} | |
1.upto(ccn.size/2) do |i| | |
n = ccn[-i*2] * 2 | |
ccn[-i*2] = n < 10 ? n : (n/10) + (n%10) | |
end | |
ccn.inject(0) {|sum, x| sum += x} % 10 == 0 | |
end | |
puts "Luhn Data" |
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
public class Sample | |
{ | |
private static boolean done; | |
public static void main(String[] args) throws InterruptedException | |
{ | |
new Thread(new Runnable() | |
{ | |
public void run() | |
{ |
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
public class SomeThreadedApp { | |
public static void main(String[] args) { | |
new Thread(new BoringRunner(), "bRunner1").start(); | |
new Thread(new BoringRunner(), "bRunner2").start(); | |
new Thread(new BoringRunner(), "bRunner3").start(); | |
} | |
static class BoringRunner implements Runnable { | |
public void run() { | |
int count = 1; |
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
import org.jruby.*; | |
import org.jruby.runtime.ThreadContext; | |
public class JavaUsingRubyLib { | |
public static void main(String[] args) { | |
Service s = new Service(); | |
Ruby rt = Ruby.getGlobalRuntime(); | |
ThreadContext ctx = rt.getCurrentContext(); | |
RubyArray response1 = (RubyArray) s.send_msg("Test message 1"); |
OlderNewer