Skip to content

Instantly share code, notes, and snippets.

View Satyam's full-sized avatar

Daniel Barreiro Satyam

  • Sitges, Barcelona, Spain
View GitHub Profile
@Satyam
Satyam / Code.js
Last active February 19, 2017 16:08
Prime birthdays on prime years
const THIS_YEAR = 2017;
const MAX_AGE = 123;
// https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
function sieveOfErathosthenes(max) {
const notPrimes = [];
const top = Math.sqrt(max);
const primes = [];
for (let i = 2; i < top; i += 1) {
@Satyam
Satyam / col-width-partial.js
Last active December 24, 2015 22:18
API docs added to `core.js` and `formatter.js` to document column definitions
/**
Adds a style `width` setting to an associated `<col>`
element for the column.
Note, the assigned width will not truncate cell content, and
it will not preserve the configured width if doing so would
compromise either the instance's `width` configuration or
the natural width of the table's containing DOM elements.
If absolute widths are required, it can be accomplished with
@Satyam
Satyam / confusing the interpreter.js
Created October 2, 2013 14:55
I tried a simple function to branch off to different functions depending on an argument, like a switch but indexed (and hopefully faster) and dynamic. I originally typed the first version in a single line in the debugging console. No need to tell me all the improvements it needs, this is not meant to be a production version. Here, I've just made…
// First version:
var goto = function (where) {
return {
a: function () {
console.log('a');
},
b: function () {
console.log('b');
}
@Satyam
Satyam / leak-test.js
Last active December 16, 2015 08:18
This is related to this conversation: https://groups.google.com/forum/?hl=en&fromgroups=#!topic/yui-contrib/hP-Qg2jLQXo. It logs DOM Nodes, cached Node instances and DOM events left behind after a test case in YUI Test. It takes a snapshot of short handles that can help identify them in the setUp() function of each test case and compares them wi…
// How to use it.
//
// This code is based on the template file that YOGI produces for unit testing
// when a module is created. Only the main changes to it are listed.
//
// Add a reference to the module in the YUI configuration section so it can locate it
// It's up to you where you put it.
YUI({
groups: {
leaks: {
@Satyam
Satyam / Bubbling Events
Created January 17, 2013 18:42
Showing how custom events (from EventTarget) can bubble up through several objects, how to add information to the event facade and what happens when they are canceled.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://yui.yahooapis.com/3.8.0/build/yui/yui.js"></script>
</head>
<body class="yui3-skin-sam">
<script>
// Create a new YUI instance and populate it with the required modules.
@Satyam
Satyam / gist:3934292
Created October 22, 2012 21:05
Views loading separate templates
YUI.add('sampleView',function(Y, NAME) {
Y.SampleView = Y.Base.create(NAME, Y.View, [], {
initializer:function(){
var self = this;
self.parallel = new Y.Parallel();
Y.io('templates/' + NAME + '.html',{
on:{
complete: self.parallel.add(function(id,response){
console.log('io completed');
self.template = response.responseText;
@Satyam
Satyam / gist:3595837
Created September 2, 2012 08:20
TreeView Speed test
YUI(
{gallery: 'gallery-2012.08.29-20-10'}
).use('gallery-yui3treeview-ng', function (Y) {
'use strict';
var count = 0,
makeBranch = function (prefix, depth) {
var branch = [], node;
count +=1;
for (var i = 0; i < 5; i+=1) {
@Satyam
Satyam / gist:2989480
Created June 25, 2012 16:04
Person.js (view)
YUI.add('personView',function(Y, NAME){
var TEMPLATES = {},
COMPILED_TEMPLATES = {};
Y.Object.each(TEMPLATES, function (template, name) {
COMPILED_TEMPLATES[name] = Y.Handlebars.compile(template);
});
Y.PersonView = Y.Base.create(
NAME,
Y.View,
[],
@Satyam
Satyam / gist:2989468
Created June 25, 2012 16:02
template server
var express = require('express'),
fs = require('fs'),
path = require('path'),
server = express.createServer(),
rexpTEMPLATE = /TEMPLATES\s*=\s*\{\s*\}/,
rexpJs = /\.js$/i,
rexpHtml = /\.html$/i,
VIEWS = '/scripts/views/',
MODELS = '/scripts/models/';
@Satyam
Satyam / gist:2988409
Created June 25, 2012 12:52
Person.View.js
YUI.add('personView',function(Y){
Y.PersonView = Y.Base.create(
'personView',
Y.View,
[],
{
initializer:function(){
this.model = this.get('model');
},
render:function(){