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) {
<!doctype html>
<html>
<head>
<title>Mithirl ES6 test</title>
<meta charset="UTF-8">
<script src="http://cdn.jsdelivr.net/mithril/0.2.0/mithril.min.js"></script>
<script src="node_modules/babel-core/browser.js"></script>
</head>
@Satyam
Satyam / ytodo.html
Created July 22, 2014 21:04
YUI App todo demo on its way to Mithril with htmlparsing of HTML templates
<!doctype html>
<html>
<head>
<title>YUI todo demo in Mithril</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mithril/0.1.18/mithril.min.js"></script>
<script src="../../node_modules/htmlparser-jresig/htmlparser-lib/htmlparser.js"></script>
<!-- This is the main container and "shell" for the todo app. -->
<script type="text/x-template" id="todo-app-template">
<div id="todo-app">
@Satyam
Satyam / ytodo.html
Created July 22, 2014 21:02
YUI App todo demo on its way to Mithril with htmlparsing of HTML templates
<!doctype html>
<html>
<head>
<title>Virtual DOM with node references</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mithril/0.1.18/mithril.min.js"></script>
<script src="../../node_modules/htmlparser-jresig/htmlparser-lib/htmlparser.js"></script>
<!-- This is the main container and "shell" for the todo app. -->
<script type="text/x-template" id="todo-app-template">
<div id="todo-app">
@Satyam
Satyam / app.js
Created June 13, 2014 16:07
Example of alternate Mithril module
/* globals Mithril, console, document */
(function (m) {
//controller
var app = function () {
// model initialization, if does not already exists
if (!app.list) {
app.list = m.request({
method: 'GET',
@Satyam
Satyam / app.js
Last active August 29, 2015 14:02
example of Mithril app
/* globals Mithril, console, document */
(function (m) {
var app = {
//models
// I keep a static copy of the list in the app
// so it doesn't get reloaded each time the route changes
// and a new app instance gets initialized
list: null,
@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.