Skip to content

Instantly share code, notes, and snippets.

app.factory('userService', ['$q', '$timeout', '$http', '$rootScope', function($q, $timeout, $http, $rootScope) {
var userService = {};
userService.tryLoginFromCookie = function() {
var promise = $q.defer();
$http({method: 'POST', url: '/login'}).
success(function(data, status, headers, config) {
$timeout(function() {
$rootScope.$broadcast('login', data);
@prettymuchbryce
prettymuchbryce / gist:8795141
Created February 4, 2014 00:13
Ruby-style random element method.
Array.prototype.sample = function() {
return this[Math.floor(Math.random() * this.length)];
}
//For node.js
if (typeof window === 'undefined' && typeof module !== 'undefined' && module.exports) {
module.exports = EasyStar;
}
function getAspectRatio() {
var ar = .8;
this.magicNumberNeverDeclaredAnywhere = 10;
ar * this.magicNumberNeverDeclaredAnywhere / 4; //divded by 4 bc why not lol. im new here u guys seem cool
var forSomeReasonAFunction = function(value) {
value = value * value / value;
this.value = value;
//Sieve of Eratosthenes
function findPrimesUpTo(value) {
var primes = [];
primes.push(false,false);
for (var i = 2; i < value; i++) {
primes.push(true);
}
for (var i = 2; i < Math.sqrt(value); i++) {
if (primes[i] == true) {
@prettymuchbryce
prettymuchbryce / gist:6471566
Created September 7, 2013 00:10
Haxe bug (HTML5/Javascript target)
package test;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
class Main extends Sprite {
private var _bitmaps:Array<Dynamic>;
//Extend function
Function.prototype.extend = function(parent) {
this.prototype = Object.create(parent.prototype);
this.prototype.constructor = this;
return this;
};
//Base Class
var BaseClass = function() {};
BaseClass.prototype.sharedMethod = function() {
@prettymuchbryce
prettymuchbryce / gist:5542020
Last active April 29, 2021 14:50
hello TypeScript & node.js
/// <reference path="./.node-definitions/node.d.ts" />
/**
* See the node.js TypeScript definition needed for this
* example here: https://github.com/borisyankov/DefinitelyTyped
*/
import Http = module('http');
class MyServer {
if (chunkX < _centerChunkX - MAX_WORLD_SIZE/2 || chunkX > _centerChunkX + MAX_WORLD_SIZE/2 || chunkY < _centerChunkY - MAX_WORLD_SIZE/2 || chunkY > _centerChunkY + MAX_WORLD_SIZE/2) {
worldChunks[chunkX + "_" + chunkY] = _waterChunk;
return _waterChunk;
}
public function showMap(playerX:uint,playerY:uint,worldProxy:WorldProxy):void {
if (!_isMapShowing) {
if (!_map) {
_map = new Sprite();
_playerBlip = new Sprite();
addChild(_map);
addChild(_playerBlip);
var renderSize:uint = WorldProxy.MAX_WORLD_SIZE + 5;