Skip to content

Instantly share code, notes, and snippets.

@lemon-tree
lemon-tree / gist:8153432
Created December 27, 2013 22:17
Issue with ENUMs in Sequelize
// This works
var Something = db.define('something', {
action: Sequelize.ENUM('OPTIONA', 'OPTIONB')
});
// This doesn't
var Something = db.define('something', {
action: {
type: Sequelize.ENUM('OPTIONA', 'OPTIONB')
}
@lemon-tree
lemon-tree / :lib:dialects:abstract:query.js
Created November 24, 2013 22:54
Fix for sequelize/sequelize#976 Difference is in lines 430 to 435
var Utils = require('../../utils')
, CustomEventEmitter = require("../../emitters/custom-event-emitter")
, Dot = require('dottie')
module.exports = (function() {
var AbstractQuery = function(database, sequelize, callee, options) {}
/**
Inherit from CustomEventEmitter
*/
@lemon-tree
lemon-tree / gist:1461911
Created December 11, 2011 18:19
Matching
<?php
$string = '/index/hi
/user/dfhds
/register/ddd
/etc/blah
/etc/';
preg_match_all("/^\/(?!(user|index|register))\w+\/\w*$/m", $string, $matches);
print_r($matches);
@lemon-tree
lemon-tree / Append.css
Created April 30, 2011 15:22
How to add some content at the bottom of the body
body:after {
content: "Content of what you want";
display: block;
}
<?php
class URL
{
public function auto($string, $type = 'both', $attr = false, $echo = false)
{
if ($type == 'both' || $type == 'url')
{
$regex = '/(?<anchor><a(?:\s+(?<attr>(?:\S+?=(?:(?:\'.*?\')|(?:".*?")\s*))+))?>(?<text>.*?)<\/a\s*>)|(?<!>)(?<url>(?<proto>https?:\/{2})(?<domain>[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,3})(?<path>\/\S*)?)/i';
return preg_replace_callback($regex, function($matches)
{
@lemon-tree
lemon-tree / LinkLocator.php
Created March 11, 2011 20:03
Replaces non-anchor wrapped urls with anchors, also filters attributes on current anchors. This is a Gist so that if you have an issue you can
<?php
$string = 'Lorem ipsum dolor sit amet, consectetur http://google.com</a> adipiscing elit. http://google.com/ Pellentesque vel lectus nec arcu malesuada eleifend eget non lectus. Nullam id tortor velit. Pellentesque ac nunc dui. Nunc dapibus, metus ac ullamcorper <a href="http://google.com" onclick="fff d">luctus</a>, arcu dolor pulvinar massa, ut gravida justo nulla a risus. Integer sit amet urna ut mauris scelerisque sollicitudin. Nulla fringilla ligula nec mi vehicula in hendrerit libero volutpat. <a href="http://google.com">http://google.com</a>';
class LinkLocator {
//If you change this regex, change the duplicate bit in the main regex. I should really be doing this progmatically
protected static $attrRegex = '(?:\S+?=(?:(?:\'.*?\')|(?:".*?")\s*))';
define('COOKIE_PREFIX', 'pre_');
function logged_in_user(){
$var = COOKIE_PREFIX."user";
if(isset($_COOKIE[$var])){
return $_COOKIE[$var];
}else{
return 'Guest';
}
}