Skip to content

Instantly share code, notes, and snippets.

@JakeCoxon
JakeCoxon / gist:1860406
Created February 18, 2012 17:59
Basic level of pinball
<?xml version="1.0"?>
<level name="Basic Level" size="480,1000">
<!-- corners -->
<wallArc at="100,100" relativeTo="topleft"
size="100,100" angles="180,270" />
<wallArc at="-100,100" relativeTo="topright"
size="100,100" angles="270,360" />
<!-- from top left to top right -->
@JakeCoxon
JakeCoxon / gist:2464656
Created April 22, 2012 15:29
Replaces url entities in a string received from Twitter API
var linkify = (function() {
var replaceSubstr = function(text, i, j, substr) {
return text.substr(0, i) + substr + text.substr(j);
}
var mergeByIndices = function(a, b) {
var i = 0, j = 0, result = [];
while (i < a.length || j < b.length) {
if (i < a.length && (j >= b.length || a[i].indices[0] < b[j].indices[0]))
result.push(a[i++]);
@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);
}
@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: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: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: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
});
for(i=0;++i<101;console.log([i,a='Fizz',b='Buzz',a+b][!(i%3)+2*!(i%5)]));
{
"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"
],
@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)
}