Skip to content

Instantly share code, notes, and snippets.

View varemenos's full-sized avatar

Adonis Kakoulidis varemenos

View GitHub Profile
@varemenos
varemenos / module.js
Last active December 21, 2015 13:09
JavaScript - Modularity
(function () {
'use strict';
// change "moduleName" to the name of the module you are making
var moduleName = {};
// do something
if (typeof module !== 'undefined' && module.exports) {
module.exports = moduleName;
} else {
@varemenos
varemenos / timer.js
Created June 7, 2013 16:53
JavaScript - Timer functionality
// from: http://stackoverflow.com/a/3969760/649239
function Timer(callback, delay) {
var timerId, start, remaining = delay;
this.pause = function() {
window.clearTimeout(timerId);
remaining -= new Date() - start;
};
@varemenos
varemenos / compare.js
Created May 25, 2013 06:48
JavaScript - Comparison results
var a = '5';
var b = new String('5');
console.log( typeof a, typeof b, a == b, a === b );
/* Output:
> string
> object
> true
@varemenos
varemenos / index.html
Created May 21, 2013 05:32
JavaScript - "Are you sure you want to leave this page"
<a href="http://stackoverflow.com/questions/7794301/window-onunload-is-not-working-properly-in-chrome-browser-can-any-one-help-me/9325742#9325742">Leave this page!</a>
@varemenos
varemenos / oop.php
Created May 16, 2013 00:24
PHP - Basic OOP
<?
class entry{
private $id = -1; // required
private $title = ""; // required
private $author = -1; // required, author ID
private $excerpt = ""; // either turn title into excerpt or manually enter one
private $date = ""; // required
// #TODO
// post type interface?
@varemenos
varemenos / 1.objectCreation.js
Created May 15, 2013 15:45
JavaScript - The basics of Object Oriented Programming
// Class creation
function Vehicle(p) {
this.brand = p.brand || "";
this.model = p.model || "";
this.wheels = p.wheels || 0;
}
// Main class' methods
Vehicle.prototype.getBrand = function () {
return this.brand;
@varemenos
varemenos / route.php
Last active December 17, 2015 08:39
PHP - Basic URL Routing
<?php
if(!empty($_REQUEST)){
// get real parameters
$parameters = $_REQUEST;
}
if(isset($_SERVER['PATH_INFO'])){
// path = the trimmed PATH_INFO string
// allowed characters:
// {'a','b',..,'z'},{'A','B',...,'Z'},{'0','1',...,'9'},{'_','/','.'}
@varemenos
varemenos / escape.js
Created April 20, 2013 05:22
JavaScript - Escape HTML special characters
// source: http://stackoverflow.com/a/9251169/649239
var escape = document.createElement('textarea');
function escapeHTML(html) {
escape.innerHTML = html;
return escape.innerHTML;
}
function unescapeHTML(html) {
@varemenos
varemenos / parseUri.js
Last active December 14, 2015 22:49
JavaScript - Parse url parameters
var params = {};
var queryString = location.search.substring(1); // For # params use location.hash
var regex = /([^&=]+)=([^&]*)/g;
var m;
while (m = regex.exec(queryString)) {
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
@varemenos
varemenos / responsive.html
Created February 28, 2013 21:12
Responsive Viewer
<html>
<head>
<meta charset="UTF-8">
<title>simple Responsive viewer by Adonis K.</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css"></link>
<style>
iframe {
transition: 150ms ease;
display: block;
margin: 0 auto;