Skip to content

Instantly share code, notes, and snippets.

View oshanz's full-sized avatar
🌴
On vacation

Oshan Wisumperuma oshanz

🌴
On vacation
View GitHub Profile
@oshanz
oshanz / sql get dates in list
Created October 2, 2014 04:47
Mysql Date List
select
selected_date
from
(select
adddate('2014-02-10', t4.i * 10000 + t3.i * 1000 + t2.i * 100 + t1.i * 10 + t0.i) selected_date
from
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0, (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1, (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2, (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3, (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where
selected_date between '2014-02-10' and '2014-02-15'
@oshanz
oshanz / list
Created October 2, 2014 15:36
Get a list of dates between two dates using javascript
function generateDateList(from, to) {
var getDate = function(date) {//Mysql Format
var m = 1 + date.getMonth(), d = date.getDate();
return date.getFullYear() + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
}
var fs = from.split('-'), startDate = new Date(fs[0], parseInt(fs[1]) - 1, fs[2]), result = [getDate(startDate)], start = startDate.getTime(), ts, end;
if ( typeof to == 'undefined') {
end = new Date().getTime();
} else {
@oshanz
oshanz / sort Mysql months
Created October 3, 2014 11:11
Sort Mysql Months
'use strict';
var _ = require('underscore');
function sortMonths(months) {
return _.intersection(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], months);
}
console.log(sortMonths(['March', 'January']));
@oshanz
oshanz / gist:f7089e0432f4509e6fd4
Created October 11, 2014 06:14
my first backbone mess
/**
* @author Waruna Oshan Wisumperuma
* @contact warunaoshan@gmail.com
* Friday, October 03 2014 16:32:36
*
*/
"use strict";
var PaginCollection, ReportModel, paginTotal = 0;
@oshanz
oshanz / serializeArray
Created October 15, 2014 08:53
serializeArray
var o = {}, a = this.$('#contactForm').serializeArray();
$j.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
@oshanz
oshanz / viewHelper
Created January 29, 2015 09:50
backbone viewHelper
sortMonths : function(months) {
return _.intersection(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], months);
}
getUniqPluck : function(arg, useCache) {
if (useCache) {
return this[arg] = this[arg] || _.uniq(_.pluck(this.List, arg)).sort();
} else {
return _.uniq(_.pluck(this.List, arg));
}
alert(([][[]]+[])[!+[]+!![]+!![]+!![]]+([]
[[]]+[])[+[]]+(!![]+[])[+[]]+([][[]]+[])
[+[]]+([]+{})[!+[]+!![]]+([][[]]+[])[!
+[]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!!
[]]+([][[]]+[])[!+[]+!![]+!![]]+([][[]]+[])
[!+[]+!![]+!![]]+(!![]+[])[+[]])
@oshanz
oshanz / ECI5266-TMA2 2014-15.txt
Last active March 27, 2020 13:12
Assignment 2 ECI5266 – Advanced Database systems
THE OPEN UNIVERSITY OF SRI LANKA
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
Assignment 2
ECI5266 – Advanced Database systems
The answers to the assignment should be sent under registered post on or before the due date to the following address or should be placed in the relevant box provided at block No. 12 of Colombo Regional Centre.
The Course Coordinator – ECI5266
Department of Electrical and Computer Engineering
Faculty of Engineering Technology
@oshanz
oshanz / date.sql
Last active August 29, 2015 14:27 — forked from johngrimes/date.sql
MySQL Date Dimension Build Script
/* Adapted from Tom Cunningham's 'Data Warehousing with MySql' (www.meansandends.com/mysql-data-warehouse) */
###### small-numbers table
DROP TABLE IF EXISTS numbers_small;
CREATE TABLE numbers_small (number INT);
INSERT INTO numbers_small VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
###### main numbers table
DROP TABLE IF EXISTS numbers;
CREATE TABLE numbers (number BIGINT);
@oshanz
oshanz / Serializor.php
Created October 16, 2015 09:07 — forked from bubba-h57/Serializor.php
Doctrine 2 Entities Serialized to JSON
<?php
namespace H57\Util;
class Serializor {
/**
* Converts the Doctrine Entity into a JSON Representation
*
* @param object $object The Object (Typically a Doctrine Entity) to convert to an array