Skip to content

Instantly share code, notes, and snippets.

Tomek Cejner tomekc

Block or report user

Report or block tomekc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tomekc
tomekc / AppDelegate.swift
Created Jan 9, 2015
CoreData snippet to add to existing project
View AppDelegate.swift
// MARK: - Core Data stack
lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "net.japko.EmptyCoreDataSwiftProject" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1] as NSURL
}()
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
@tomekc
tomekc / SwiftNinja2.swift
Created Aug 5, 2014
Solution to Ray Wenderlich's Swift Ninja challenge
View SwiftNinja2.swift
// Solution to ultimate Swift Nija challenge
// http://www.raywenderlich.com/77845/swift-ninja-part-2
enum Suit {
case Clubs, Diamonds, Hearts, Spades
}
enum Rank {
case Jack, Queen, King, Ace
case Num(Int)
View puzzle15.html
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="">
<style type="text/css">
* {
@tomekc
tomekc / Optional+getOrElse.swift
Last active Oct 28, 2016
Add .getOrElse() method to Swift's Optional<T>, to unwrap value with fallback to default value. Idea borrowed from Scala language.
View Optional+getOrElse.swift
// An extension to Optional type:
// getOrElse() will return optional's value if exists, otherwise the default value provided as argument will be returned.
//
// Note: Since Xcode6 beta 5, you can use '??' operator.
//
// (c) Tomek Cejner 2014
// @tomekcejner
extension Optional {
func getOrElse(val:T) -> T {
if self != nil {
View composer_scene.lua
local composer = require( "composer" )
local scene = composer.newScene()
-- include Corona's "physics" library
local physics = require "physics"
function scene:create( event )
-- Called when the scene's view does not exist.
--
-- INSERT code here to initialize the scene
View objects_in_lua.lua
-- Table based object with method
function newPerson(name)
local M = {
name = name,
age = 0,
}
M.greet = function (self)
print ("This is " .. self.name .. ", I am " .. self.age)
@tomekc
tomekc / bmf.lua
Last active Jan 1, 2016
Bitmap font support in Corona SDK, compatible with Graphics 2.0
View bmf.lua
module( ..., package.seeall )
-- AngelCode bitmap font support
-- Updated for Graphics 2.0
-- Download sprite module from https://github.com/coronalabs/framework-sprite-legacy/raw/master/sprite.lua
local sprite = require( "sprite" )
-- Specify an Angelcode format bitmap font definition file (".FNT")
-- The spritesheet(s) that this file references need to be located in the resource directory.
@tomekc
tomekc / Game.h
Created Dec 13, 2013
Sparrow Framework 2.0 boilerplate
View Game.h
#import <Foundation/Foundation.h>
#import <Sparrow-Framework/Sparrow.h>
@interface Game : SPSprite
@end
@tomekc
tomekc / .gitignore
Created Nov 24, 2013
.gitignore for Xcode and AppCode projects. Collected from internet's collective wisdom :]
View .gitignore
# xcode noise
build/*
*.perspective
*.perspectivev3
*.pbxuser
*.xcworkspace
*.mode1
*.mode2v3
*.mode1v3
xcuserdata
@tomekc
tomekc / absurd_rest_service.js
Created Jul 4, 2013
Before running, install express by running npm install express and run with: node absurd_rest_service.js in this script's directory. Then: To submit calculation to curl -i -H "Content-Type: application/json" -d '{ "operation" : "+", "operands" : [ 2,3] }' http://localhost:3000/calculations To see results, use link from response: curl http://loca…
View absurd_rest_service.js
/*
Before running, install express by running
npm install express
and run with:
node absurd_rest_service.js
in this script's directory.
You can’t perform that action at this time.