Skip to content

Instantly share code, notes, and snippets.

View chanakasan's full-sized avatar

Chanaka Abeysinghe chanakasan

View GitHub Profile
# config.yml
fos_rest:
format_listener:
rules:
- { path: ^/, priorities: [ json, xml, html ], fallback_format: ~, prefer_extension: false }
view:
view_response_listener: force
sensio_framework_extra:
view: { annotations: false }
guard :shell do
watch(%r{^spec/.+Spec.php}) { |m|
system("clear")
system("bin/phpspec run --no-interaction --format=pretty #{m[0]}")
}
watch(%r{^src/(.+).php}) {
system("clear")
system("bin/phpspec run --no-interaction --format=pretty")
}
<?php
if (file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
return false; // serve the requested resource as-is.
} else {
include_once 'index.php';
}
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
<?php
/**
* Password hash generator
*
* @static
* @param string $password
* @return string
*/
public static function passwordHash ($password)
<?php
/**
* Return URL-Friendly string slug
* @param string $string
* @return string
*/
function seoUrl($string) {
//Unwanted: {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
$string = strtolower($string);
/**
* insertTextAtCursor
* An Utility function
* @param href
* @param selectedText
*/
function insertTextAtCursor(href, selectedText) {
var html = "<a href='" + href + "'>" + selectedText + "</a>";
var selectPastedContent = false;
var sel, range;
@chanakasan
chanakasan / contacts.js
Last active August 29, 2015 14:15 — forked from troyk/contacts.js
// Don't care much about inheritance at this point, but I'll probably attempt it at
// some point via cloning ancestor schema's
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var Contact = new Schema({
_type: String,
name: String
});
/*
* Selenium WebDriver JavaScript test with Mocha and NodeJS
*
* Start with: SELENIUM=PATH_TO_SELENIUM_JAR/selenium-server-standalone-2.31.0.jar mocha -t 10000 -R list google-sample.js
*
* Download selenium-server-standalone-2.31.0.jar from https://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar
* 'sudo su' and 'npm install -g colors mocha selenium-webdriver'
*
* http://visionmedia.github.io/mocha/
* https://code.google.com/p/selenium/wiki/WebDriverJs
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do