Skip to content

Instantly share code, notes, and snippets.

@roine
roine / gist:4115823
Created November 20, 2012 03:48
css transition callback in js
myElement.addEventListener("transitionend", function() {
alert('transition completed')
}, true);
@roine
roine / main.js
Created November 28, 2012 02:30
track the users history
(function(window){
// add ability to save an object
if(localStorage){
Storage.prototype.setObj = function (key, obj) {
return this.setItem(key, JSON.stringify(obj));
}
Storage.prototype.getObj = function(key) {
return JSON.parse(this.getItem(key));
@roine
roine / inheritance.js
Created November 28, 2012 10:17
inheritance javascript
// create an object a and clone it in b
var a = {
init:function(){return 'hello'}
}, b = Object.create(a);
// check the values
a.init(); // hello
b.init(); // hello
// set a new return value to init
class Author {
private $firstName;
private $lastName;
public function __construct($firstName, $lastName) {
$this->firstName = $firstName;
$this->lastName = $lastName;
}
public function getFirstName() {
return $this->firstName;
}
//compare two distinct array
// check for length and value at each index
function equalArrays(a,b) {
if (a.length != b.length) return false;
for(var i = 0; i < a.length; i++)
if (a[i] !== b[i]) return false;
return true;
}
@roine
roine / oop.js
Created December 10, 2012 08:57
var MyClass = function(options) {
/* create a private variable */
privateOpt = options;
/* create a public variable*/
this.opt = options;
/* to access this variable into the method */
var that = this;
false == false // true
0 == false // true
-0 == false // true
'' == false //true
// converting to a Number will return 0
// exemple:
@roine
roine / gshow.sh
Created December 18, 2012 06:22
pretty git show
git show --pretty="format:" --name-only HEAD
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.8.3",function($,L){$('form').submit(function () {if($(".jon-submit:checkbox").is(":checked")){return;}var $that = $(this),formWidth = $(this).width(),checkbox = $(document.createElement('input')).prop('type', 'checkbox').addClass('jon-submit').css({'width': 22,'float': 'none','height': 17,margin:0,padding:0,'font-size':12}),checkboxWrapper = $(document.createElement('div')).append(checkbox).append("Submit form").css({'background':'white','width': formWidth,'z-index':2000,'padding':'2px 10px','margin':'2px 0','border-radius':3,'border':'1px solid silver','text-align':'center','box-shadow': '0 0 5p
@roine
roine / demo.html
Last active December 11, 2015 16:59
<style>
kbd {
padding: 0.1em 0.6em;
border: 1px solid #ccc;
font-size: 11px;
font-family: Arial,Helvetica,sans-serif;
background-color: #f7f7f7;
color: #333;
-moz-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;