Skip to content

Instantly share code, notes, and snippets.

.knob {
width: 40px;
height: 40px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
position: relative;
background-color: #F6F4F4;
background-color: #f2f0f0;
background-image: -moz-linear-gradient(top, #f6f4f4, #edebeb);
@JakeCoxon
JakeCoxon / CombinedIterator.scala
Created January 13, 2014 17:53
An iterator that iterates two secondary iterators in parallel
class CombinedIterator[A, B](first: Iterator[A], second: Iterator[B]) extends Iterator[(Option[A], Option[B])] {
def hasNext = first.hasNext || second.hasNext
def next = (if (first.hasNext) Some(first.next) else None, if (second.hasNext) Some(second.next) else None)
}
@JakeCoxon
JakeCoxon / fieldmap.scala
Created November 16, 2013 16:56
Typed Field Map
object EntityFields {
import collection.immutable.Map
class FieldPair[T](field : Field[T], value : T) extends (Field[T], T)(field, value)
class Field[T](val default : Option[T]) {
def this() = this(None)
def this(default : T) = this(Some(default))
def ~>(value : T) = new FieldPair[T](this, value)
}
{
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"dictionary": "Packages/Language - English/en_GB.dic",
"font_size": 11.0,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
for(i=0;++i<101;console.log([i,a='Fizz',b='Buzz',a+b][!(i%3)+2*!(i%5)]));
@JakeCoxon
JakeCoxon / gist:5511725
Created May 3, 2013 17:33
Sort an array by multiple fields
// Sort an array
array.sort(function(A, B) {
var a, b;
return (((a = A.field1) > (b = B.field1)) - (b > a)) || // Sort by field1
(((a = A.field2) > (b = B.field2)) - (b > a)) // Sort by field2
});
@JakeCoxon
JakeCoxon / gist:4168274
Created November 29, 2012 11:12
Build Sink
#!/usr/bin/ruby
file = IO.read("src/embs/Sink.java")
sinks_choice = []
sinks_choice << [
{:id=>1, :channel=>0, :panid=>11, :n=>10, :t=>500, :start=>300},
{:id=>2, :channel=>1, :panid=>12, :n=>4, :t=>700, :start=>300},
{:id=>3, :channel=>2, :panid=>13, :n=>5, :t=>1500, :start=>300}]
@JakeCoxon
JakeCoxon / gist:3775689
Created September 24, 2012 12:22
Ruby + Java file
//;"
/*"
code = <<-CODE.chop
class AJavaClass {
public static void main(String[] args) {
System.out.println("#{Random.rand(100)}");
}
}
CODE
@JakeCoxon
JakeCoxon / gist:3456453
Created August 24, 2012 22:27
Ruby to_h
###
module Enumerable
# maps an array into a hash
def to_h(&block)
inject({}) {|hash, *v| block.call(hash, *v); hash}
end
end
class NilClass
@JakeCoxon
JakeCoxon / gist:2949013
Created June 18, 2012 15:46
Drawing straight lines
// This can be used for a basic line instead of making a texture yourself
Pixmap pixmap = new Pixmap(1, 1, Format.RGB565);
pixmap.setColor(1f, 1f, 1f, 1f);
pixmap.drawPixel(0, 0);
pixelTexture = new Texture(pixmap);
pixelTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
public void drawLine(SpriteBatch batch, float x1, float y1, float x2, float y2, float width) {
drawLine(batch, pixelTexture, x1, y1, x2, y2, width);
}