Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / quest1.java
Created January 30, 2012 23:40
infinate set (countability of rational numbers)
abstract class ATree {
Rational value;
ATree(Rational value){
this.value = value;
}
abstract Node expandOneLevel();
// returns the integer value of the node/leaf
public Double doubleValue(){
return this.value.toDouble();
@nixpulvis
nixpulvis / gist:1926289
Created February 27, 2012 19:03
Simple Ciclic Data
import tester.Tester;
class Star {
String name;
Movie movie;
Star(String name){
this.name = name;
}
Star(String name, Movie movie){
this.name = name;
@nixpulvis
nixpulvis / Hex -> Color
Created May 17, 2012 17:47
This if a function to convert hex strings into r, g, b color. This function returns multiple variables.
-- converts hex colors to 0-1 colors for use in World of Warcraft.
function V.HexToColor(hex)
local color = { }
if strlen(hex) == 6 or strlength(hex) == 8 then
for i = 1, 8, 2 do
if strsub(hex, i, i+1) == "" then print(strsub(hex, i, i+1)) break end
-- converting string to number 0-1
tinsert(color, tonumber(strsub(hex, i, i+1), 16)/255)
end
else
@nixpulvis
nixpulvis / gist:2779607
Created May 24, 2012 05:17
repositioning from child
mover:SetScript("OnDragStart", function()
local lastX, lastY = GetCursorPosition()
mover:SetScript("OnUpdate", function()
local x, y = GetCursorPosition()
xOff, yOff = x-lastX, y-lastY
lastX, lastY = x, y
for i = 1, frame:GetNumPoints() do
local point, relativeTo, relativePoint, xOffset, yOffset = frame:GetPoint(i)
@nixpulvis
nixpulvis / gist:2890564
Created June 7, 2012 18:20
Dynamic content require (for interpreted languages)
# returns an array of files that are required by the given file
def get_requirements( file )
requirements = Array.new
File.readlines("#{file}.rb").each do |line|
regex = /(?<=require.')(.*)(?=';)/ # matches the requirements in a file
requirement = line.match(regex)
if requirement
requirements << requirement.to_s
end
end
@nixpulvis
nixpulvis / markdown.less
Created July 11, 2012 03:25 — forked from theconektd/github.css
Github Markdown CSS - for Markdown Editor Preview
.markdown {
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
def sieve( n )
s = (2..n).to_a
s.each { |p| next unless p; break if p**2 > n; (p**2).step(n, p) { |m| s[m-2] = nil } }
s.compact
end
def time
start = Time.now
yield
Time.now - start
@nixpulvis
nixpulvis / chain_assignment.rb
Created August 21, 2012 17:50
Sexy Chain Assignment
sum += e *= month_days[i]
@nixpulvis
nixpulvis / easyjava
Created September 10, 2012 05:24
Simple and Easy way to run a java class.
#!/usr/bin/env ruby
# ## An Easy Way to Compile and Run Java Classes
#
# System utility for compiling and running Java classes
# in a specific directory structure.
#
# #### Recommended Installation
# Save this code to a file named `easyjava`, somewhere on your HD. Then
# in your `~/.bash_profile` add the following:
@nixpulvis
nixpulvis / gist:3763424
Created September 21, 2012 19:33
quick and dirty assertEquals
private void assertEquals (String name, Object a, Object b) {
if (! a.equals(b)) {
System.out.println ("***** Test failed ***** "
+ name + ": " + totalTests);
System.out.println (" A => " + a);
System.out.println (" b => " + b);
totalErrors = totalErrors + 1;
}
totalTests = totalTests + 1;
}