Skip to content

Instantly share code, notes, and snippets.

View alejandrolechuga's full-sized avatar
🤯
Focusing

neptuno alejandrolechuga

🤯
Focusing
View GitHub Profile
(function(number){
console.log(number); // 2
number = 1;
console.log(arguments[0]); // 1
}(2));
(function(number){
"use strict";
console.log(number); // 2
number = 1;
//Routing
hrouter("home", function () {
$('#text').html("Home ! ");
});
//Parameters
hrouter("home/:page", function (page) {
$('#text').html("Home page #" + page);
});
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
var coords = new google.maps.LatLng(32.49847,-116.962852);
function initialize() {
var mapOptions = {
zoom: 15,
center: coords
};
@alejandrolechuga
alejandrolechuga / gcd.js
Created February 26, 2014 08:44
Euclid's Algorithm , Greatest Common Divisor
// Gets the greatest common divisor
function gcd(p, q) {
if (q == 0) return p;
// remainder
var r = p % q;
return gcd(q, r);
}
function run_length_encoding (string) {
var encoded = "";
var i = string.length;
var counter = 1;
var character;
var temp;
temp = string.charAt(i-1);
while(i--) {
character = string.charAt(i-1);
if (temp == character && i > 0) {
YUI.namespace("module");
YUI.module = (function () {
return {
publicmethod: function () {
return "hello world";
}
}
}());
(function (){
var Shape = function (type) {
var shapes = {
straight: [
[1,1,1,1,1]
],
square: [
[1,1],
[1,1]
@alejandrolechuga
alejandrolechuga / isUniqueCharString.js
Created May 26, 2014 05:40
Unique Characters checker
function uniquewords(string) {
var length = string.length,
chars = {};
// it should
if (length > 256) return false;
for (var i = 0; i < length; i++) {
if (!chars[string[i]]){
chars[string[i]] = true;
} else {
return false;
function textToBin(text) {
var length = text.length,
output = [];
for (var i = 0;i < length; i++) {
var bin = text[i].charCodeAt().toString(2);
output.push(Array(8-bin.length+1).join("0") + bin);
}
return output.join(" ");
}
textToBin("!a") // => "00100001 01100001"
@alejandrolechuga
alejandrolechuga / observe.js
Last active August 29, 2015 14:11
Observe
var model = {};
Object.observe(model, function(changes){
changes.forEach(function(change){
console.log(change.type, change.name, change.oldValue);
});
});
model.name = "Pluto"; // Observe log => add name undefined
model.name = "Mars"; // Observe log => update name Pluto