Skip to content

Instantly share code, notes, and snippets.

View toriaezunama's full-sized avatar

Paul Wadsworth toriaezunama

  • Bluescape
  • Vancouver BC Canada
View GitHub Profile
@toriaezunama
toriaezunama / scrollView-basic.lua
Created January 12, 2012 02:36
#lua #corona #template #scrollView widget basic usage
local widget = require "widget"
local scroller = widget.newScrollView{
width = 320,
height = 480,
scrollWidth = 700,
scrollHeight = 1000
}
local obj = display.newImage( "myobject.png" )
obj.x = 400
@toriaezunama
toriaezunama / module-template.lua
Created March 30, 2012 03:01
#corona #module #template #lua
--[[
== Example use ==
...
]]
--== Built in functions
local assert = assert
local error = error
local pairs = pairs
local ipairs = ipairs
@toriaezunama
toriaezunama / deferred.lua
Created April 2, 2012 04:16
#lua #deferred #jquery
--[[
== Example use ==
local Deferred = require( 'lib.deferred' )
local unitOfProcessing = function( aDefer )
local closure = function() aDefer:resolve( "hi there" ) end
timer.performWithDelay( 2000, closure )
end
defer = Deferred.new( unitOfProcessing )
#### View the change history of a file ####
gitk [filename]
#### How to grep in the git history ####
git grep <regexp> $(git rev-list --all)
#### Changing the message on the last commit
git commit --amend -m "New message"
@toriaezunama
toriaezunama / gist:3344709
Created August 13, 2012 23:10
print recursive function #lua #moai #corona
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if ( print_r_cache[ tostring(t) ] ) then
print( indent .. "*" .. tostring(t) )
else
print_r_cache[ tostring(t) ]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
@toriaezunama
toriaezunama / gist:3439321
Created August 23, 2012 17:44
#cakephp #cheatsheet
// Get version of cakephp
print( "Version: " . Configure::version() );
@toriaezunama
toriaezunama / gist:8107250
Created December 24, 2013 00:56
Lua metatable masking
local t = {}
local mt = { x = 5 }
setmetatable( t, { __index = mt } )
-- No t.x so metatable referenced
print( 1, t.x ) --> 5
-- Add t.x (masking mt.x)
t.x = 4
print( 2, t.x ) --> 4
@toriaezunama
toriaezunama / gist:8107755
Last active January 1, 2016 06:49
Simple module definition that prevents overwriting globals by accident *N.B. This won't work on Lua >= 5.2 because of the new _ENV*
local M = {
__index = _G,
__newindex = function( t, k, v )
if rawget( _G, k ) ~= nil then
print( string.format( "Setting key '%s', on table %s masks a value in _G!!", tostring( k ), tostring( t ) ) )
error()
else
rawset( t, k, v )
end
///// View controller /////
#include "CGCustomPropertyLayer.h"
- (void)viewDidLoad
{
[super viewDidLoad];
_layer = [CGCustomPropertyLayer new];
[self.customLayerView.layer addSublayer:_layer];
_layer.bounds = self.customLayerView.bounds;
/// An object that has some tear-down logic
public protocol Disposable {
func dispose()
}
/// An event provides a mechanism for raising notifications, together with some
/// associated data. Multiple function handlers can be added, with each being invoked,
/// with the event data, when the event is raised.
public class Event<T> {