Skip to content

Instantly share code, notes, and snippets.

View s9tpepper's full-sized avatar

Omar Gonzalez s9tpepper

View GitHub Profile
@s9tpepper
s9tpepper / usingCursorGetNextDocument.as
Created July 10, 2011 01:01
Using the Cursor object getNextDocument() method
/* Once the Cursor is returned to the callback the Cursor's
getNextDocument() method can be used to handle each of
the documents returned */
function onCursorReady(cursor:Cursor):void
{
// Get the first document
var doc:Object = cursor.getNextDocument();
// If there was a first document, do something and get next.
@s9tpepper
s9tpepper / usingCursorToArrayMethod.as
Created July 10, 2011 01:07
Using the Cursor object toArray() method
/* Alternatively, once the Cursor is returned to the callback the Cursor's
toArray() method can be used to retrieve an Array of all the documents that
the Cursor object has loaded. */
function onCursorReady(cursor:Cursor):void
{
// Get array of all documents
var documents:Array = cursor.toArray();
// Do something, such as add it to a data provider
@s9tpepper
s9tpepper / usingTheCursorGetMoreMethod.as
Created July 10, 2011 01:13
Using the Cursor object getMore() method
/* The getMore() method can be used to load more documents from the database
if getNextDocument() returns null.*/
function onCursorReady(cursor:Cursor):void
{
/*...do stuff...*/
// Before calling getMore() make sure hasMore() returns true.
if (cursor.hasMore())
{
cursor.getMore().add(onGotMore);
@s9tpepper
s9tpepper / usingTheInsertMethod.as
Created July 10, 2011 01:18
Using the insert() method
/* Use a Document object to build the BSON document to save into the database */
const newDocument:Document = new Document();
newDocument.put("name", "Hello from Flash sucka!");
/* Use the insert() method to save. This method does not return anything */
mongo.db("myDatabase").collection("myCollection").insert(newDocument);
/* Use a getLastError command to get the status of the last insert attempt. */
mongo.db("myDatabase").runCommand(new Document("getLastError:")).addOnce(onLastError);
@s9tpepper
s9tpepper / usingTheRemoveMethod.as
Created July 10, 2011 01:24
Using the remove() method
/* Retrieve the _id property from a document returned by mongodb. */
var objectId:ObjectID = documentRetrievedFromMongo._id;
/* Create a selector query using the Document object to specify by _id
which document to remove() */
var selector:Document = new Document();
selector.put("_id", objectId);
/* Call the remove function, there is no return. */
mongo.db("myDatabase").collection("myCollection").remove(selector);
@s9tpepper
s9tpepper / gist:1094408
Created July 20, 2011 05:36
Getting a Stage reference in FlexUnit test for AS3-only project
// This is in an ActionScript Project in Flash Builder
// Inside FlexUnitApplication.as I added a UI testing environment
// In the builder I pass in a reference to the FlexUnitApplication instance
package
{
import com.project.MyClassTests;
import flash.display.Sprite;
@s9tpepper
s9tpepper / gist:1394507
Created November 25, 2011 21:57
modal styles
var css:CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration('global');
css.setStyle('modalTransparency', transparency);
css.setStyle('modalTransparencyColor', color);
css.setStyle('modalTransparencyBlur', blur);
css.setStyle('modalTransparencyDuration', duration);
@s9tpepper
s9tpepper / backgroundOpacityLessMixin
Created April 7, 2012 19:17
Element Background Opacity w/out affecting children
/* The opacity: .5 CSS property will make the container and its
* children transparent. This LESS mixin can be used to set the
* background-color property with opacity resulting in a transparent
* background color with full opacity children.
*/
.backgroundOpacityRGB(@red: 0, @green: 0, @blue: 0, @bgOpacity: 0.5) {
background: rgb(@red, @green, @blue); // Fallback to full opacity bg
background: rgba(@red, @green, @blue, @bgOpacity); // Alpha'd bg color for 'modern' browsers
}
@s9tpepper
s9tpepper / angularJSServices
Created April 9, 2012 06:31
AngularJS Services
// In AngularJS 0.9.19
// Dont do...
angular.service("CustomServiceOne", function($resource) {
return $resource("/path/to/api/:aParam", {}, {
getSomething: {method: "GET", params: {aParam: 0}, isArray: false}
});
});
// Instead do this...
@s9tpepper
s9tpepper / modifyAngularDefaultRequestContentTypeHeader.js
Created August 11, 2012 23:56
Modify Default Content-Type for Angular.js POST/PUT requests
// The .config() part is the relevant part, 'SomeModule' is arbitrary name,
// but this config() call goes on your main ng-app="YourAppModule"
// The PHP $_POST expects data w/ a form content type, not a JSON payload
angular.module("YourAppModule", ["SomeModule"]).config(function($httpProvider) {
$httpProvider.defaults.headers.put['Content-Type'] =
'application/x-www-form-urlencoded';
$httpProvider.defaults.headers.post['Content-Type'] =
'application/x-www-form-urlencoded';
});