Skip to content

Instantly share code, notes, and snippets.

Edwin Dalorzo edalorzo

  • Costa Rica
Block or report user

Report or block edalorzo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View base64.js
(function(){
var index = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/','='];
var octets = ["","0","00","000","0000","00000","000000","0000000"];
var sixths = ["","00000","0000","000","00","0"];
var paddings = [[],[],[64,64],[],[64]];
View arithmetic-eval.js
unction Value(value){
this.value = value || 0;
}
Value.prototype.eval = function(){ return this; };
Value.prototype.valueOf = function(){ return this.value.valueOf(); };
Value.prototype.toString = function(){ return this.value.toString(); };
var createOperator = function(){
function reduce(oper){
View roman-numerals.js
asDecimal = function(){
var romans = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000 };
return function(roman){
return roman.split('').map(function(r){ return romans[r];})
.reduce(function(res,n,i,digits){
var prev = i > 0 ? digits[i-1] : 0;
return prev < n ? res + n - 2 * prev : res + n;
},0);
};
}();
View Operands.java
import java.util.Objects;
import java.util.Arrays;
interface Operand {
Operand neg();
Operand add(Int that);
Operand add(Decimal that);
Operand add(Operand that);
Operand mult(Int that);
@edalorzo
edalorzo / .ignore
Created May 22, 2016
IntelliJ .ignore
View .ignore
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
@edalorzo
edalorzo / Factors.java
Created May 4, 2016
Largest Factor of a Number
View Factors.java
public class Factors {
public static long factors(long n) {
long max = 0;
long d = 2;
while (n > 1) {
while (n % d == 0) {
max = Math.max(max, d);
n /= d;
}
@edalorzo
edalorzo / Palindrome.java
Created May 4, 2016
Largest Palindrome Number
View Palindrome.java
public class Palindrome {
private static boolean isPalindrome(long n) {
return reverse(n) == n;
}
private static long reverse(long n) {
long rev = 0L;
while (n > 0) {
long d = n % 10;
@edalorzo
edalorzo / Primes.java
Last active May 5, 2016
Infinite Primes Generator
View Primes.java
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.LongPredicate;
import java.util.function.LongSupplier;
import java.util.stream.LongStream;
/**
* Primes generator.
*/
View streams.sml
datatype 'a stream = Empty | Cons of 'a * (unit -> 'a stream)
fun from n = Cons(n, fn () => from(n +1))
val naturals = from(1)
fun filter f xs =
case xs of
Empty => Empty
| Cons(h,t) => if f(h)
then Cons(h, fn () => filter f (t()))
@edalorzo
edalorzo / StreamConcat.java
Created Sep 14, 2014
Stream Concatenation
View StreamConcat.java
public static <T> Stream<T> concatenate(Stream<T>... streams) {
return Stream.of(streams).reduce(Stream.empty(), Stream::concat);
}
public static void main(String[] args) {
Stream<? extends CharSequence> res = concatenate(
Stream.of("One"),
Stream.of(new StringBuffer("Two")),
Stream.of(new StringBuilder("Three"))
You can’t perform that action at this time.