Skip to content

Instantly share code, notes, and snippets.

View vaskoz's full-sized avatar
🏠
Working from home

Vasko Zdravevski vaskoz

🏠
Working from home
View GitHub Profile
class Ninja{private final String test="This is just a test String";private Ninja(){}public String getTest(){return test;}}
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.
# 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
# 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)
public class ThreadNinja {
private int rank;
public synchronized void fight(ThreadNinja enemy) {
if (!enemy.canDefend(this)) {
rank++;
}
}
public synchronized boolean canDefend(ThreadNinja enemy) {
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'
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"
public class Sample
{
private static boolean done;
public static void main(String[] args) throws InterruptedException
{
new Thread(new Runnable()
{
public void run()
{
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;
@vaskoz
vaskoz / JavaUsingRubyLib.java
Created December 15, 2010 01:53
Want to use Ruby functionality in Java? Compile it into a JAR
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");