Skip to content

Instantly share code, notes, and snippets.

View richistron's full-sized avatar
:octocat:
Coding like a baws

Ricardo Rivas richistron

:octocat:
Coding like a baws
View GitHub Profile
@richistron
richistron / private_closure.js
Created March 2, 2014 17:17
Private values inside object clusure
/**
* Object with hidden values
*/
var ObjectClosure = (function(){
var privateValue = "hello there!!";
return {
getValue: function(){
return privateValue;
},
setValue: function(newValue){
@richistron
richistron / bg-image.scss
Last active August 29, 2015 14:17
background sass mixin
@mixin bg-image($image) {
// other properties
background-image: image-url($image);
// other properties
}
.myclass {
@include bg-image('asadas.jpg');
}
$(selector).bind("change", function() {
return $.ajax({
success: function() {
return $(this).hide(function() {
return $(this).show("slow", function() {
return mainCallback(function() {
return alert("Hola Mundo");
});
});
});
@richistron
richistron / thisJS.coffee
Created August 22, 2013 00:22
Usando this con coffeeScript
(($)->
class Test
constructor:(@error = null)->
log: ->
if window.log? and error is not null then console.log @error
select: ->
$elements = $("div")
$elements.on "click" , ->
###
En este momento @ = this es un elemento de jquery
<?php
$db = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$sql = sprintf("SELECT contenido FROM barra_lateral WHERE 1 ");
echo '<div id="barra_lateral">';
foreach($db->query($sql) as $row){
echo '<div class="item">' . $row['contenido'] . '<br></div>';
@richistron
richistron / ns_and_class.js
Last active December 23, 2015 23:09
Respuesta a Cristian Camilo Chaparro
/*
No se si en en entendí to pregunta, pero me suena a estos posibles casos
*/
// Herencia de un objeto
// padre
var Parent = (function(){
@richistron
richistron / Javascript_FAQS.md
Last active March 30, 2016 22:02
This was a presentation

Javascript FAQS

js

How can I create a function which only runs just one time?

I have a method that is running multiple times and I'm not sure why. Since this method does a ajax call, I don't want to fetch the same data twice.

@richistron
richistron / trivia_interval.js
Created April 4, 2016 22:51
Pregunta de javascript
// Quiero crear un loop que corra cada 1000 miliseconds, pero que espere a que
// el anterior termine
// incorrecto: http://g.recordit.co/p8ssRrRY27.gif
// correcto: http://g.recordit.co/OFFYS9Nd6F.gif
function doStuff(){
setTimeout(function(){
console.log('done doing stuff');
}, 3000);
};

Setup babel + gulp + jasmine + browserify + babelify

ES2015 it's awesome and babel.js is a great tool for compiling ES2015 into javascript code. If you take a look at babel's documentation, you'll find out over than 20 different ways to install babel.js from node to .NET. One of the greatets features in ES2015 is import and export but you can't use it in the browser :( right out of the box. If you want to use modules in the browser you will need to do a trick and use browserify + babelify.