Skip to content

Commit

Permalink
Merge pull request #1 from BitOfGold/master
Browse files Browse the repository at this point in the history
change by BitOfGold
  • Loading branch information
krisxoofoo committed Jun 6, 2015
2 parents 92c42c5 + 501862d commit db9ba85
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 1 deletion.
14 changes: 13 additions & 1 deletion public/app/models/code_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ function listBits($allVersions = true){
if($allVersions){
$sql = 'select * from `bits` ORDER BY created DESC';
} else {
$sql = 'select *, MAX(`bits`.version) as latestVersion from `bits` GROUP BY `bits`.slug ORDER BY created DESC';
$sql = '
SELECT f.*,
x.lv as latestVersion
FROM (
SELECT slug, MAX(version) as lv
FROM bits
GROUP BY slug
) as x
INNER JOIN
bits as f
ON f.slug = x.slug
AND f.version = x.lv
ORDER BY f.created DESC';
}
$res = $this->query($sql);
if($res){
Expand Down
4 changes: 4 additions & 0 deletions public/static/js/Bits.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ $.fn.injectObject=function(data){var els=this.find(':input').get();if(arguments.
// Hotkeys
(function(jQuery){jQuery.hotkeys={version:"0.8",specialKeys:{8:"backspace",9:"tab",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",191:"/",224:"meta"},shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":": ","'":"\"",",":"<",".":">","/":"?","\\":"|"}};function keyHandler(handleObj){if(typeof handleObj.data!=="string"){return}var origHandler=handleObj.handler,keys=handleObj.data.toLowerCase().split(" ");handleObj.handler=function(event){if(this!==event.target&&(/textarea|select/i.test(event.target.nodeName)||event.target.type==="text")){return}var special=event.type!=="keypress"&&jQuery.hotkeys.specialKeys[event.which],character=String.fromCharCode(event.which).toLowerCase(),key,modif="",possible={};if(event.altKey&&special!=="alt"){modif+="alt+"}if(event.ctrlKey&&special!=="ctrl"){modif+="ctrl+"}if(event.metaKey&&!event.ctrlKey&&special!=="meta"){modif+="meta+"}if(event.shiftKey&&special!=="shift"){modif+="shift+"}if(special){possible[modif+special]=true}else{possible[modif+character]=true;possible[modif+jQuery.hotkeys.shiftNums[character]]=true;if(modif==="shift+"){possible[jQuery.hotkeys.shiftNums[character]]=true}}for(var i=0,l=keys.length;i<l;i++){if(possible[keys[i]]){arguments[0].preventDefault();return origHandler.apply(this,arguments)}}}}jQuery.each(["keydown","keyup","keypress"],function(){jQuery.event.special[this]={add:keyHandler}})})(jQuery);

window.btoa = function(str) {
return(Base64.encode(str));
}

/*
*
*
Expand Down
216 changes: 216 additions & 0 deletions public/static/js/base64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
Copyright (c) 2008 Fred Palmer fred.palmer_at_gmail.com
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
function StringBuffer()
{
this.buffer = [];
}

StringBuffer.prototype.append = function append(string)
{
this.buffer.push(string);
return this;
};

StringBuffer.prototype.toString = function toString()
{
return this.buffer.join("");
};

var Base64 =
{
codex : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

encode : function (input)
{
var output = new StringBuffer();

var enumerator = new Utf8EncodeEnumerator(input);
while (enumerator.moveNext())
{
var chr1 = enumerator.current;

enumerator.moveNext();
var chr2 = enumerator.current;

enumerator.moveNext();
var chr3 = enumerator.current;

var enc1 = chr1 >> 2;
var enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
var enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
var enc4 = chr3 & 63;

if (isNaN(chr2))
{
enc3 = enc4 = 64;
}
else if (isNaN(chr3))
{
enc4 = 64;
}

output.append(this.codex.charAt(enc1) + this.codex.charAt(enc2) + this.codex.charAt(enc3) + this.codex.charAt(enc4));
}

return output.toString();
},

decode : function (input)
{
var output = new StringBuffer();

var enumerator = new Base64DecodeEnumerator(input);
while (enumerator.moveNext())
{
var charCode = enumerator.current;

if (charCode < 128)
output.append(String.fromCharCode(charCode));
else if ((charCode > 191) && (charCode < 224))
{
enumerator.moveNext();
var charCode2 = enumerator.current;

output.append(String.fromCharCode(((charCode & 31) << 6) | (charCode2 & 63)));
}
else
{
enumerator.moveNext();
var charCode2 = enumerator.current;

enumerator.moveNext();
var charCode3 = enumerator.current;

output.append(String.fromCharCode(((charCode & 15) << 12) | ((charCode2 & 63) << 6) | (charCode3 & 63)));
}
}

return output.toString();
}
}


function Utf8EncodeEnumerator(input)
{
this._input = input;
this._index = -1;
this._buffer = [];
}

Utf8EncodeEnumerator.prototype =
{
current: Number.NaN,

moveNext: function()
{
if (this._buffer.length > 0)
{
this.current = this._buffer.shift();
return true;
}
else if (this._index >= (this._input.length - 1))
{
this.current = Number.NaN;
return false;
}
else
{
var charCode = this._input.charCodeAt(++this._index);

// "\r\n" -> "\n"
//
if ((charCode == 13) && (this._input.charCodeAt(this._index + 1) == 10))
{
charCode = 10;
this._index += 2;
}

if (charCode < 128)
{
this.current = charCode;
}
else if ((charCode > 127) && (charCode < 2048))
{
this.current = (charCode >> 6) | 192;
this._buffer.push((charCode & 63) | 128);
}
else
{
this.current = (charCode >> 12) | 224;
this._buffer.push(((charCode >> 6) & 63) | 128);
this._buffer.push((charCode & 63) | 128);
}

return true;
}
}
}

function Base64DecodeEnumerator(input)
{
this._input = input;
this._index = -1;
this._buffer = [];
}

Base64DecodeEnumerator.prototype =
{
current: 64,

moveNext: function()
{
if (this._buffer.length > 0)
{
this.current = this._buffer.shift();
return true;
}
else if (this._index >= (this._input.length - 1))
{
this.current = 64;
return false;
}
else
{
var enc1 = Base64.codex.indexOf(this._input.charAt(++this._index));
var enc2 = Base64.codex.indexOf(this._input.charAt(++this._index));
var enc3 = Base64.codex.indexOf(this._input.charAt(++this._index));
var enc4 = Base64.codex.indexOf(this._input.charAt(++this._index));

var chr1 = (enc1 << 2) | (enc2 >> 4);
var chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
var chr3 = ((enc3 & 3) << 6) | enc4;

this.current = chr1;

if (enc3 != 64)
this._buffer.push(chr2);

if (enc4 != 64)
this._buffer.push(chr3);

return true;
}
}
};

0 comments on commit db9ba85

Please sign in to comment.