Skip to content

Instantly share code, notes, and snippets.

View edysegura's full-sized avatar
👽
Always learning!

Edy Segura edysegura

👽
Always learning!
View GitHub Profile
@edysegura
edysegura / browser-detection.js
Last active September 16, 2015 23:03
[JS] Browser Detection
var result = navigator.userAgent.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i);
//output: ["Chrome/41.0.2272.76", "Chrome", "41.0.2272.76", ".76"]
@edysegura
edysegura / method-pointer.groovy
Last active June 23, 2016 20:03
Groovy's Magic
def out = System.out.&println
out "Haaa!" //Haa
@edysegura
edysegura / myClosure.js
Last active September 16, 2015 23:06
[JS] A closure example in JavaScript to hold the context
function myClosure(name) {
var x = 0;
//private method
function doCount() {
console.log("Count " + name + ", count: " + x++);
}
//public
return {
@edysegura
edysegura / directive.js
Created December 12, 2014 12:57
How to observer an attribute in AngularJS directive
return function(scope, element, attrs) {
attrs.$observe('key', function(value) {
console.log('key=', value);
});
}
@edysegura
edysegura / hasFruit.js
Last active February 29, 2016 16:59
[JS] Check if has values with some
var fruits = [
{name:'apple', color:'red'},
{name:'orange', color:'orange'},
{name:'grape', color:'purple'}
];
var hasFruit = function(fruitToCheck) {
return fruits.some(function(fruit) {
return fruit.name === fruitToCheck;
});
def "Should return the number of events for each month of all events"() {
given:
controller.eventService = Mock(EventService) {
historyReport() >> [
"2012": ["eventCount" : 6, "monthlyCount" : ["December" : 4, "November" : 1, "January" : 1]],
"2011": ["eventCount" : 3, "monthlyCount" : ["October" : 3]]
]
}
when:
@edysegura
edysegura / EventService.groovy
Created November 27, 2014 18:54
Grails Goodness: Using Hibernate Native SQL Queries
package com.ericsson.tv.saas.portal
import org.hibernate.transform.AliasToEntityMapResultTransformer
class EventService {
def sessionFactory
def historyReport(currentUser) {
def report = [:]
@edysegura
edysegura / Todo.groovy
Last active August 29, 2015 14:05
Groovy learning - Todo Case
public class Todo {
def name
def note
public static void main(String[] args) {
def todos = [
new Todo([name:'1', note:'One']),
new Todo([name:'2', note:'Two']),
new Todo([name:'3', note:'Three']),
@edysegura
edysegura / extend-html-dom.js
Last active September 16, 2015 23:12
[JS] How to extend the HTML DOM?
HTMLElement.prototype.remove = function() {
this.parentNode.removeChild(this);
};
document.querySelector("#a").remove();
@edysegura
edysegura / html5-validation-message.js
Last active March 27, 2025 09:41
How to prevent the browser from showing default HTML5 validation error message bubble?
document.addEventListener('invalid', (function(){
return function(e) {
//prevent the browser from showing default error bubble / hint
e.preventDefault();
// optionally fire off some custom validation handler
// myValidation();
};
})(), true);