Skip to content

Instantly share code, notes, and snippets.

@icambridge
icambridge / gist:4454572
Created January 4, 2013 17:56
Shows that the variable created within the scope of the begin end isn't destoryed after the loop.
people = ['one','two','three','four']
counter = 0;
begin
person = people[counter]
puts person
counter = counter + 1
end while not people[counter].nil?
@icambridge
icambridge / Blog.scala
Created December 24, 2012 18:43
Play! 2 Form binding
def save = Action { implicit request =>
val result = postForm.bindFromRequest.fold(
{formFail => Ok(views.html.admin.blog.edit(formFail))},
{post => Ok(views.html.blog.post(post))}
)
result
}
@icambridge
icambridge / Blog.scala
Created December 24, 2012 17:41
Get post data from Play2 Scala
val postData = request.body.asFormUrlEncoded.get
val emptyValue = Seq("")
val title = postDate.get("title").getOrElse(emptyValue)(0)
@icambridge
icambridge / Blog.scala
Last active December 10, 2015 02:09
Scala Options <3
def post(slug: String) = Action {
val blogPostOption = postModel.getPost(slug)
blogPostOption match {
case Some(blogPost) => Ok(views.html.blog.post(blogPost))
case None => Ok(views.html.blog.notfound())
}
}
<?php
class Invoice
{
/**
* @ORM\OneToMany(targetEntity="InvoiceLine", mappedBy="invoiceId")
*/
private $lines;
}
import com.typesafe.startscript.StartScriptPlugin
seq(StartScriptPlugin.startScriptForClassesSettings: _*)
name := "hello"
version := "1.0"
scalaVersion := "2.9.1"
@icambridge
icambridge / Uri.scala
Created March 25, 2012 16:16
Uri Escape
object Uri {
def escape(unsafe: String) = {
val alphabet = List[String]("a","b","c","e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x","y","z")
var safe = ""
unsafe.split("").foreach { char =>
if (alphabet.indexOf(char.toLowerCase) == -1 && char.forall(_.isDigit) == false) {
safe += "%"
@icambridge
icambridge / gist:2146327
Created March 21, 2012 11:34
Reflection fail
<?php
$reflection = new ReflectionObject($proxy);
$content = $reflection->getProperty('content ');
$content->setAccessible(true);
$_content = $content->getValue($proxy);
$this->assertEquals("content", $_content);
/**
Is there any packages that would cause the Model/Entity to return true on a save/update but
not actually update the field?
I've got a test that passes locally but fails on the Jenkins server. PHP and Mongo Extenstions
versions are 5.3.2 and 1.2.6 on the Jenkins server and 5.3.9 and 1.2.6 locally.
@icambridge
icambridge / validateChange.php
Created February 29, 2012 18:52
Change the validation rules
<?php
$user = User:create();
// Get the validation rules.
$userModel = new User();
$rules = $userModel->validates;
// Add new
$rules['password']['skipEmpty'] = true;
$rules['confirm_password'] = array(