Posts

Showing posts with the label Function

Create Function From SQL Script By Liquibase

Answer : I think you need to add the endDelimiter clause in the Liquibase tag, based on the documentation found here Below is an example <changeSet author="newbie" id="function_rad2deg" dbms="mysql,h2"> <sqlFile encoding="utf8" path="sql/function_rad2deg.sql" relativeToChangelogFile="true" splitStatements="false" stripComments="false" endDelimiter="\nGO" /> </changeSet> Your SQL file with the above delimiter would then look like DROP FUNCTION IF EXISTS rad2deg; GO CREATE FUNCTION rad2deg(rad DOUBLE) RETURNS DOUBLE BEGIN RETURN (rad * 180 / PI()); END GO Hope this helps With above example there are two problems one is it will not work on h2 and 2 is splitStatements should be true: <changeSet author="me" id="01_functions_mysql" dbms="mysql"> <sqlFile encoding...

Converting Multiple Columns From Character To Numeric Format In R

Answer : You could try DF <- data.frame("a" = as.character(0:5), "b" = paste(0:5, ".1", sep = ""), "c" = letters[1:6], stringsAsFactors = FALSE) # Check columns classes sapply(DF, class) # a b c # "character" "character" "character" cols.num <- c("a","b") DF[cols.num] <- sapply(DF[cols.num],as.numeric) sapply(DF, class) # a b c # "numeric" "numeric" "character" If you're already using the tidyverse, there are a few solution depending on the exact situation. Basic if you know it's all numbers and doesn't have NAs library(dplyr) # solution dataset %>% mutate_if(is.character,as.numeric) Test cases df <- data.frame( x1 = c('1','2','3'), x2 = c('4','5','6'), x3 = c(...

Calling Private Function Within The Same Class Python

Answer : There is no implicit this-> in Python like you have in C/C++ etc. You have to call it on self . class Foo: def __bar(self, arg): #do something def baz(self, arg): self.__bar(arg) These methods are not really private though. When you start a method name with two underscores Python does some name mangling to make it "private" and that's all it does, it does not enforce anything like other languages do. If you define __bar on Foo , it is still accesible from outside of the object through Foo._Foo__bar . E.g., one can do this: f = Foo() f._Foo__bar('a') This explains the "odd" identifier in the error message you got as well. You can find it here in the docs. __bar is "private" (in the sense that its name has been mangled), but it's still a method of Foo , so you have to reference it via self and pass self to it. Just calling it with a bare __bar() won't work; you have to call i...

Anchor Jumping By Using Javascript

Answer : You can get the coordinate of the target element and set the scroll position to it. But this is so complicated. Here is a lazier way to do that: function jump(h){ var url = location.href; //Save down the URL without hash. location.href = "#"+h; //Go to the target element. history.replaceState(null,null,url); //Don't like hashes. Changing it back. } This uses replaceState to manipulate the url. If you also want support for IE, then you will have to do it the complicated way: function jump(h){ var top = document.getElementById(h).offsetTop; //Getting Y of target element window.scrollTo(0, top); //Go there directly or some transition }​ Demo: http://jsfiddle.net/DerekL/rEpPA/ Another one w/ transition: http://jsfiddle.net/DerekL/x3edvp4t/ You can also use .scrollIntoView : document.getElementById(h).scrollIntoView(); //Even IE6 supports this (Well I lied. It's not ...