Skip to content

Instantly share code, notes, and snippets.

View nramirez's full-sized avatar
lion mode!

Naz nramirez

lion mode!
View GitHub Profile
@nramirez
nramirez / gist:4e3ad8369dde3ede282b
Created January 18, 2015 20:26
Sum of Intervals
function sumIntervals(intervals){
var uniArr = [intervals[0]], helper = true;
intervals.reduce(function(lastInt, actualInt){
uniArr.map(function(e){
if (!helper) {return};
//This validates if the array contains the klk[0]
if (actualInt[0] >= e[0] && actualInt[0] <= e[1]) {
if(e[1] < actualInt[1])
e[1] = actualInt[1];
helper = false;
function removeZeros(array) {
// Sort "array" so that all elements with the value of zero are moved to the
// end of the array, while the other elements maintain order.
// [0, 1, 2, 0, 3] --> [1, 2, 3, 0, 0]
// Zero elements also maintain order in which they occurred.
// [0, "0", 1, 2, 3] --> [1, 2, 3, 0, "0"]
var length = array.length;
for(var i =0; length > 0; i++, length--){
if(array[i] == 0){
var temp = array[i];
@nramirez
nramirez / gist:ccffcb0cf90e8f169eaf
Created January 19, 2015 20:43
removeZeros_without_specials
function removeZeros(array){
//Get initial zero index
var nextZero = getNextIndex(array,0);
var movedCounter = 0;
//If no zeros exists then we return the array
if (nextZero == -1) { return array};
while(nextZero < (array.length - movedCounter)){
//Copy the temporary zero, cause it could be a string or a number
var temp = array[nextZero];
move(array, nextZero);
var sum = function(number){
return p(number, number);
}
var memo = [];
var p = function (n, m){
if (m == 0 ) { return 0;};
if (n == 0) { return 1};
if (n < 0) { return 0};
if (memo[n] == undefined) memo[n] = [];
var result = memo[n][m];
var Sudoku = function(data)
{
// Private methods
// -------------------------
var sudoku = data;
var sudokuLength = sudoku[0].length;
var uniqueAndValidNumber = function(array){
var arr = array.slice().sort(), i;
for( i= arr.length; i--;) {
//The number shouldn't be repeated, has to be a number and couldn't be bigger than the length
@nramirez
nramirez / gist:3802b889ecd99ff3e1db
Created January 22, 2015 18:36
Human readable duration format
var formatDuration = function(duration){
var result = '',
tempTime =0,
durations = [
{ description : 'year', plural: "years", range : 31536000 },
{ description : 'day', plural: "days", range : 86400 },
{ description : 'hour', plural: "hours", range : 3600 },
{ description : 'minute', plural: "minutes", range : 60 },
{ description : 'second', plural: "seconds", range : 1 }
];
@nramirez
nramirez / gist:f7729ff768657b85d60d
Last active August 29, 2015 14:14
Sum of (Two) Squares
var allSquaredPairs = function(n){
var max = Math.sqrt(n),
posibles = [],
temp =0,
result = [],
i =0;
for(; i<=max; i++)
{
//Reference http://stackoverflow.com/questions/5380323/whats-the-fastest-algorithm-to-represent-a-prime-as-sum-of-two-squares
temp = Math.sqrt(n-i*i);
@nramirez
nramirez / gist:0c274c9c101114555eea
Last active August 29, 2015 14:14
Complex CSV Parser
function parseCSV(input, separator, quote) {
separator = separator || ',';
quote = quote || '"';
var tempWord ='', c ='', temp = [],
closingPosition, result =[], specialCharacters = '$\\',
doubleQuoteRegex = new RegExp(quote+quote, 'g');
if (specialCharacters.indexOf(quote) > -1) {
doubleQuoteRegex = new RegExp('\\' +quote+ '\\' +quote, 'g');
};
@nramirez
nramirez / javascript_resources.md
Last active August 29, 2015 14:14 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@nramirez
nramirez / playlist.jsx
Last active January 9, 2016 18:51
Wedding playlist
var data = [];
var playlist = React.createClass({
getInitialState: function(){
return { lastSong: 0 }
},
componentDidMount: function() {
setInterval(this.loadSongs, 5000);
},
loadSongs: function() {