Get duplicates ints in array in 126 Characters with Java 8 and Streams

August 10, 2016 Leave a comment
*(excluding line breaks, and spaces)

int[] GetDuplicates(int[] n) {
    return 
        Arrays.stream(n)
        .distinct()
        .filter(i -> {
            int c = 0;
            for(int x : n)
                c += x==i ? 1 : 0;
            return c>1;
        })
        .toArray();
}
Categories: Java, Mini-tips, Programación, Tips

Split string in oracle sql query

August 1, 2016 1 comment

select regexp_substr('MyString,otherString,lastOneStr','[^,]+', 1, 2) from dual; 
-- Returns 'otherString' String
Categories: Beyond, Mini-tips, Oracle, plsql, SQL, Tips

Get TZH:TZM from TZR in oracle sql query

July 18, 2016 Leave a comment

SELECT TZ_OFFSET('US/Pacific') FROM DUAL;

Categories: Mini-tips, Oracle, plsql

Replace commas on string JavaScript

June 14, 2016 Leave a comment

var mystring = "This is a string, with commas, or, is it?";
var result = mystring.replace(/,/g , "|");

Categories: Beyond, JavaScript, Mini-tips

Check when deleting, inserting or updating in trigger oracle db

June 6, 2016 Leave a comment

— Inside your trigger

IF DELETING THEN
— do your thing when deleting
END IF;

IF INSERTING THEN
— do your thing when inserting
END IF;

IF UPDATING THEN
— do your thing when updating
END IF;

Categories: Mini-tips, Oracle, plsql, SQL, Tips

Simple grant/revoke select on view Oracle DB

May 17, 2016 Leave a comment

grant select on my_schema.my_new_view to schema_that_will_see_it;
commit;

revoke select on my_schema.my_new_view from schema_that_will_see_it;
commit;

Simple Moore Majority Algorithm

April 13, 2016 Leave a comment

Assuming there is always a majority number and that the array has length > 0


public int mooreMajority(int nums[]){
        int result = 0, count = 0;
        for(int x : nums){
            if(count == 0) result = x;
            if(x == result) count++;
            else count--;
        }
        return result;
}