Skip to content

Instantly share code, notes, and snippets.

var xMin:int = Math.ceil(_cameraX/_tileSize) - _entityRenderLeeway;
var yMin:int = Math.ceil(_cameraY/_tileSize) - _entityRenderLeeway;
var xMax:int = xMin + _stageWidth/_tileSize+2 + _entityRenderLeeway;
var yMax:int = yMin + _stageHeight/_tileSize+2 + _entityRenderLeeway;
for (var i:uint = 0; i < _loot.length; i++) {
if (_loot[i].x >= xMin && _loot[i].x <= xMax && _loot[i].y >= yMin && _loot[i].y <= yMax) {
_loot[i].image.visible = true;
if (!_loot[i].isBeingPickedUp) {
_loot[i].image.x = Math.floor(_loot[i].x * _tileSize - Loot.IMAGE_SIZE - _cameraX);
@prettymuchbryce
prettymuchbryce / gist:4422628
Last active December 10, 2015 10:39
Performant tile rendering with Starling
//How to accomplish perfomant tile rendering with the Starling engine.
package {
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.ui.Keyboard;
import starling.display.Image;
import starling.display.Sprite;
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 12:31:3d:03:40:17 brd ff:ff:ff:ff:ff:ff
inet 10.117.79.229/23 brd 10.117.79.255 scope global eth0
inet6 fe80::1031:3dff:fe03:4017/64 scope link
valid_lft forever preferred_lft forever
require 'open-uri'
require 'ImageUtilities' #ImageUtilities is a module that is used to grab screenshots of a given URL. It is an external API.
require 'cgi'
require 'LatestCache' #LatestCache is a module that is used to update the cache for entries that have been submitted recently.
class EntriesController < ApplicationController
before_filter :authenticate, :only => "destroy" #User must have admin privileges to destroy an entry.
# This index method is hit via ajax call from javascript. It is the "HOT", or front page entries.
def index
page = params[:page] #Url Param can tell us which entry to start from. This is in the case that the user is scrolling down the page. Eatch "batch" of entries is a "page".
def isPalindrome(value)
list = value.split("")
j = 0
i = list.length-1
while j <= i
if value[j] != value[i]
return false
end
j+=1
i-=1
@prettymuchbryce
prettymuchbryce / gist:3783986
Created September 25, 2012 19:41
Ruby Quicksort
class QuickSort
def recurse(low, high)
i = low
j = high
pivot = @list[(low + (high-low)/2).floor]
while i <= j
while @list[i] < pivot
i+=1
@prettymuchbryce
prettymuchbryce / gist:3768553
Created September 23, 2012 02:08
Javascript Priority Queue Implementation
//Constants
PriorityQueue.MAX_HEAP = 0;
PriorityQueue.MIN_HEAP = 1;
/**
* This is an improved Priority Queue data type implementation that can be used to sort any object type.
* It uses a technique called a binary heap.
*
* For more on binary heaps see: http://en.wikipedia.org/wiki/Binary_heap
*
@prettymuchbryce
prettymuchbryce / gist:3745462
Created September 18, 2012 19:56
Find minimum swaps to order a string of 0's and 1's
def findOperations(string)
operations = 0
list = string.split("")
startIndex = 0
endIndex = list.length-1
while startIndex < endIndex
if list[endIndex]=="0"
if list[startIndex] == "1"
list[startIndex], list[endIndex] = list[endIndex], list[startIndex]
operations = operations+1
@prettymuchbryce
prettymuchbryce / gist:3719773
Created September 14, 2012 04:28
Dictionary with Trie Tree
class Node
attr_accessor :endOfWord, :children
def initialize()
@endOfWord = false
@children = {}
end
end
class Dictionary
@prettymuchbryce
prettymuchbryce / Dictionary.java
Created September 14, 2012 02:26
Dictionary with trie tree Java
//Dictionary implemented using a Trie Tree.
public class Dictionary {
private HashMap<Character,Node> roots = new HashMap<Character,Node>();
/**
* Search through the dictionary for a word.
* @param string The word to search for.
* @return Whether or not the word exists in the dictionary.
*/
public boolean search(String string) {