Skip to content

Instantly share code, notes, and snippets.

@eridal
eridal / code-zens.md
Created August 20, 2014 18:00
Code Zen
  • In the world of open-source development where most of the code is shared, code clarity and readability is important.
  • Object-oriented code architecture allows for much higher clarity and readability than procedural one, especially in complex code.
  • Clean and eloquent code is easier to review and independently reviewed code is more reliable and secure.
  • Code clarity largely influences the code's reusability for other purposes and by other people.
  • Consistency in a coding standard allows for cleaner and more comprehensible documentation.
  • Although it requires some tedious work, the usage of semantic checks on a massive scale pays off with more reliable code.
  • Adapting some of the familiar conventions that are used for method naming, parameter ordering, and method behavior from othe languages is better than making up new ones.
  • Unvarying return types with a fixed type for every method is better than varying return types when a value of one type can be mistaken for a value of another type.
  • Underscores
@eridal
eridal / Java.java
Last active August 29, 2015 14:06
PHP to Java persistent process comunication
import java.util.Scanner;
class Java {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (s.hasNextInt()) { // <-- blocking read
int i = s.nextInt();
@eridal
eridal / Compiler.java
Last active August 9, 2023 13:26
Java to PHP Compilation
package j2p;
import japa.parser.JavaParser;
import japa.parser.ParseException;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.ImportDeclaration;
import japa.parser.ast.PackageDeclaration;
import japa.parser.ast.body.BodyDeclaration;
import japa.parser.ast.body.ClassOrInterfaceDeclaration;
import japa.parser.ast.body.FieldDeclaration;
{
init: function(elevators, floors) {
var waiting = [];
elevators.forEach(function (elevator) {
elevator.on("idle", function() {
var i = waiting.length;
while (i-- > 0) {
<?php
$url = 'http://cdn01.ib.infobae.com/adjuntos/162/rss/Infobae.xml';
$xml = simplexml_load_string(
file_get_contents($url)
);
foreach ($xml->channel->item as $item) {
echo strip_tags($item->title);
Do what you can, with what you have, where you are.
- Theodore Roosevelt

Every man dies, but not every man truly lives.
- William Wallace

Life is hard, it's harder if you're stupid.
- John Wayne
@eridal
eridal / simple.js
Created October 30, 2015 17:11 — forked from paton/simple.js
Super simple implementation of define() and require() used in Localize.js (https://localizejs.com)
var define, require;
(function() {
var modules = {};
require = function(name) {
return modules[name]();
};
define = function(name, fn) {
@eridal
eridal / ical-parser.js
Created May 10, 2016 20:45
iCal format parser
'use strict';
function convert(fileData, callback) {
if (typeof fileData !== "string") {
return callback(
new Error("Invalid file data passed.")
);
}
@eridal
eridal / monitorEvents.js
Created November 23, 2016 23:55 — forked from PaulKinlan/monitorEvents.js
monitorEvents.js
function monitorEvents(element) {
var log = function(e) { console.log(e);};
var events = [];
for(var i in element) {
if(i.startsWith("on")) events.push(i.substr(2));
}
events.forEach(function(eventName) {
element.addEventListener(eventName, log);
});
@eridal
eridal / adivinar.psc
Created July 2, 2017 14:49
Algoritmos PSeInt
Algoritmo AdivinarMiNumero
Definir secreto Como Entero
Definir adivino Como Entero
secreto <- aleatorio(1, 100)
oportunidades <- 10
Imprimir "Acabo de pensar un numero entre 1 y 100..."