tag:blogger.com,1999:blog-26990059047600250132024-03-12T19:55:57.177-07:00Thermal JaHeroA blog dedicated to my technical and non-technical experiences on work, events, trips and life in general. paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-2699005904760025013.post-65784704251090364972019-12-14T01:48:00.001-08:002019-12-14T01:48:03.719-08:00<br />
<span style="background-color: white; color: #242729; display: inline; float: none; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">I met an issue related to "could not create Vfs.Dir from url, no matching UrlType was found" and the solution I applied was by adding change logs class to DatabaseConfiguration.</span><br />
<br />
<br />
<br />
This is the error.<br />
<br />
<code>
org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/home/jhipster/app.war]
either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
at org.reflections.vfs.Vfs.fromURL(Vfs.java:109)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
at org.reflections.Reflections.scan(Reflections.java:240)
at org.reflections.Reflections.scan(Reflections.java:202)
at org.reflections.Reflections.<init>(Reflections.java:123)
at org.reflections.Reflections.<init>(Reflections.java:168)
at org.reflections.Reflections.<init>(Reflections.java:141)
at com.github.mongobee.utils.ChangeService.fetchChangeLogs(ChangeService.java:50)
at com.github.mongobee.Mongobee.executeMigration(Mongobee.java:169)
at com.github.mongobee.Mongobee.execute(Mongobee.java:156)
at com.github.mongobee.Mongobee.afterPropertiesSet(Mongobee.java:126)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1753)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1690)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at com.novanus.platform.masternodectrl.MasternodeCtrlApp.main(MasternodeCtrlApp.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:58)
2019-12-14 09:37:06.243 INFO 1 --- [ main] com.github.mongobee.Mongobee : Mongobee is releasing process lock.
2019-12-14 09:37:06.251 INFO 1 --- [ main] com.github.mongobee.Mongobee : Mongobee has finished his job.
2019-12-14 09:37:07.441 WARN 1 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
</code>
<br />
<br />
Just add class under <app_package>.config.dbmigrations <br />
<br />
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'Menlo'; font-size: 9.0pt;"><span style="color: #bbb529;">@ChangeLog</span><span style="color: #cc7832;">public class </span>DatabaseChangelog {
}</pre>
<br />
And the annoying error was gone.<br />
<br />
<br />
<br />paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-45283265363057667302018-01-17T05:48:00.001-08:002018-01-17T06:57:04.197-08:00Standalone Selenium Driver Log LevelStandalone Selenium Driver Log Level<br />
<br />
I had too much trouble today trying to minimise selenium driver logs, only to find out you only need to pass environment option upon starting selenium just like below. Just sharing this one for others sake. :)<br />
<br />
<code>
# Log levels are the following to choose from: OFF, SEVERE, WARNING, INFO, DEBUG, FINE, FINER, FINEST, ALL
<br /><br />
java -jar -Dselenium.LOGGER.level=WARNING /opt/selenium/selenium-server-standalone.jar
</code>
<br />
<br />
You can also set log file like:<br />
<br />
<code>
java -jar -Dselenium.LOGGER=/tmp/my_file.log /opt/selenium/selenium-server-standalone.jar
</code>
<br />
<br />
You can do more experiments if needed. Play around. Enjoy!paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-34995453745084150522015-12-20T07:01:00.002-08:002015-12-20T07:03:48.744-08:00Angular variable with HTML containing directives compiled via custom directive<span style="font-family: Arial, Helvetica, sans-serif;">This is a code snippet that allows one to compile a scope variable value who contains both HTML and angular directives.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Simple way to deal with it is through this script...</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">On html:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><div ng-bind-html-compile="someVariable"></div></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">On angular controller:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">$scope.personName="Mark";</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">$scope.someVariable="<b>Hello, </b> {{personName}} !!!";</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">On angular directive:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">app.directive('ngBindHtmlCompile', ['$compile', function ($compile) {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> return {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> restrict: 'A',</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> link: function (scope, element, attrs) {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> scope.$watch(function () {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> return scope.$eval(attrs.bindHtmlCompile);</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }, function (value) {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> element.html(value && value.toString());</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> var compileScope = scope;</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> if (attrs.bindHtmlScope) {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> compileScope = scope.$eval(attrs.bindHtmlScope);</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> $compile(element.contents())(compileScope);</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> });</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> };</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">}]);</span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-8997377973603071262015-10-15T08:58:00.000-07:002015-10-15T08:58:11.441-07:00Java - Finding Frequent Phrases in a Large File Effeciently<span style="font-family: Trebuchet MS, sans-serif;">October 15, 2015 - I was bored so I went to play around with Java and solve some simple problem or exercise below to energize my playful mind.</span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Given a large file that does not fit in memory
(say 10GB), find the top 100000 most frequent
phrases. The file has 50 phrases per line separated
by a pipe (|). Assume that the phrases do not
contain pipe.</b></span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br />Example line may look like: </span><br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Foobar Candy | Olympics 2012 | PGA | CNET | Microsoft Bing ….<br /></span><div>
<span style="font-family: Trebuchet MS, sans-serif;">The above line has 5 phrases in visible region.</span></div>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><a name='more'></a><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Solution:</b></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">{actual method}</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><div>
public List<Map.Entry<String,Integer>> findTopHundredThousandFrequentPhrases(String folderPath, String fileName) {</div>
<div>
Map<String, Integer> occurrences = new HashMap<>();</div>
<div>
<br /></div>
<div>
Path path = Paths.get(folderPath, fileName);</div>
<div>
try (BufferedReader br = Files.newBufferedReader(path, Charset.forName("UTF-8"))) {</div>
<div>
String line;</div>
<div>
while ((line = br.readLine()) != null) {</div>
<div>
String[] phrases = line.split("\\|");</div>
<div>
for (String phrase: phrases) {</div>
<div>
if (!occurrences.containsKey(phrase)) {</div>
<div>
occurrences.put(phrase, 1);</div>
<div>
} else {</div>
<div>
occurrences.put(phrase, occurrences.get(phrase) + 1);</div>
<div>
}</div>
<div>
}</div>
<div>
}</div>
<div>
} catch (IOException ioe) {</div>
<div>
ioe.printStackTrace();</div>
<div>
return Collections.emptyList();</div>
<div>
}</div>
<div>
<br /></div>
<div>
List<Map.Entry<String, Integer>> hashMapEntries = new ArrayList<>(occurrences.entrySet());</div>
<div>
Collections.sort(hashMapEntries, (e1, e2) -> Integer.compare(e2.getValue(), e1.getValue()));</div>
<div>
<br /></div>
<div>
return hashMapEntries</div>
<div>
.stream()</div>
<div>
.limit(100000).collect(Collectors.toList());</div>
<div>
}</div>
<div>
<br /></div>
<div>
{support class}</div>
<div>
<br /></div>
<div>
<div>
public class ComplementaryPair {</div>
<div>
public int addendOne;</div>
<div>
public int addendTwo;</div>
<div>
<br /></div>
<div>
public ComplementaryPair(int addendOne, int addendTwo) {</div>
<div>
this.addendOne = addendOne;</div>
<div>
this.addendTwo = addendTwo;</div>
<div>
}</div>
<div>
<br /></div>
<div>
public int sum() {</div>
<div>
return addendOne + addendTwo;</div>
<div>
}</div>
<div>
<br /></div>
<div>
@Override</div>
<div>
public String toString() {</div>
<div>
return addendOne + " + " + addendTwo;</div>
<div>
}</div>
<div>
<br /></div>
<div>
@Override</div>
<div>
public boolean equals(Object o) {</div>
<div>
if (this == o) return true;</div>
<div>
if (o == null || getClass() != o.getClass()) return false;</div>
<div>
<br /></div>
<div>
ComplementaryPair that = (ComplementaryPair) o;</div>
<div>
<br /></div>
<div>
Set<Integer> numbers = new HashSet<>(</div>
<div>
Arrays.asList(</div>
<div>
that.addendOne, that.addendTwo, addendOne, addendTwo</div>
<div>
));</div>
<div>
<br /></div>
<div>
return numbers.size() <= 2;</div>
<div>
<br /></div>
<div>
}</div>
<div>
<br /></div>
<div>
@Override</div>
<div>
public int hashCode() {</div>
<div>
int result = addendOne + addendTwo;</div>
<div>
result = 31 * result;</div>
<div>
return result;</div>
<div>
}</div>
<div>
}</div>
</div>
</span></div>
<div>
<br /></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">I may be wrong but hopefully I got this right. Feel free to comment or let me know your thoughts.</span></div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com1tag:blogger.com,1999:blog-2699005904760025013.post-81566920521572856682015-10-15T08:51:00.002-07:002015-10-15T08:51:45.085-07:00Java - Finding K-complementary Pairs in Array of Integers<span style="font-family: Trebuchet MS, sans-serif;">October 15, 2015 - I was bored so I went to play around with Java and solve some simple problem or exercise below to energize my playful mind.</span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Write an efficient algorithm to find K-complementary
pairs in a given array of integers. Given Array A,
pair (i, j) is K- complementary if K = A[i] +
A[j];</b></span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"></span></span><br />
<a name='more'></a><span style="font-family: Trebuchet MS, sans-serif;"><b>Solution:</b></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> public Set<ComplementaryPair> findComplementaryPairs(int sum, int[] numbers) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> if (numbers == null || numbers.length < 2) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> return new HashSet<>();</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> Set<Integer> noneDuplicate = new HashSet<>();</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> for(int number:numbers) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> noneDuplicate.add(number);</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> Set<ComplementaryPair> complementaryPairs = new HashSet<>();</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> for (Integer number: noneDuplicate) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> if (number > sum) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> continue;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> int difference = sum - number;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> if (noneDuplicate.contains(difference)) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> complementaryPairs.add(new ComplementaryPair(number, difference));</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> return complementaryPairs;</span></span><br />
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span><span style="font-family: 'Trebuchet MS', sans-serif;">I may be wrong but hopefully I got this right. Feel free to comment or let me know your thoughts.</span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-26627756519397993742015-10-15T08:42:00.002-07:002015-10-15T09:00:27.742-07:00Java - Check if a String is a Palindrome<span style="font-family: Trebuchet MS, sans-serif;">October 15, 2015 - I was bored so I went to play around with Java and solve some simple problem or exercise below to energize my playful mind.</span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Write an efficient algorithm to check if a string
is a palindrome. A string is a palindrome if the
string matches the reverse of string.</b></span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;">Example: 1221 is a palindrome but not 1121.</span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"></span></span><br />
<a name='more'></a><span style="font-family: Trebuchet MS, sans-serif;"><b>Solution:</b></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">public boolean isPalindrome(String data) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> if (data == null) return false;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> char[] dataChars = data.toCharArray();</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> if (dataChars.length < 2) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> return false;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> int leftIndex = 0, rightIndex = (dataChars.length - 1);</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> while (rightIndex > leftIndex) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> if (dataChars[leftIndex] != dataChars[rightIndex]) {</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> return false;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> leftIndex++;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> rightIndex--;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> return true;</span></span><br />
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> }</span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="font-family: 'Trebuchet MS', sans-serif;">I may be wrong but hopefully I got this right. Feel free to comment or let me know your thoughts.</span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-38455675218195083532015-10-15T07:56:00.000-07:002015-10-15T09:14:24.352-07:00MySQL - Overlapping Date Range Filter<span style="font-family: 'Trebuchet MS', sans-serif;">October 15, 2015 - I was bored so I went to play around with MySQL and solve some simple problem or exercise below to energize my playful mind.</span><br />
<span style="line-height: 0.53cm;"><br /></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b>I have a table for bugs from a bug tracking
software; let’s call the table “bugs”. The
table has four columns (id, open_date, close_date,
severity). On any given day a bug is open if the
open_date is on or before that day and close_date
is after that day. For example, a bug is open
on “2012-01-01”, if it’s created on or before
“2012-01-01” and closed on or after “2012-01-02”.
I want a SQL to show number of bugs open for
a range of dates.</b></span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b><br /></b></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">CREATE TABLE bugs (</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> id INT,</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> severity INT,</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> open_date DATE,</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> close_date DATE</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">);</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">INSERT INTO bugs VALUES</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> (</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> 1, </span></span><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 20.0314960479736px;">1,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2011-12-31', '%Y-%m-%d'),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2011-12-31', '%Y-%m-%d')</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> (</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> 2, </span></span><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 20.0314960479736px;">1,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-01', '%Y-%m-%d'),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-02', '%Y-%m-%d')</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> (</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> 3, </span></span><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 20.0314960479736px;">1,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-03', '%Y-%m-%d'),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-03', '%Y-%m-%d')</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> (</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> 4, </span></span><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 20.0314960479736px;">1,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-03', '%Y-%m-%d'),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-04', '%Y-%m-%d')</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> (</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> 5, </span></span><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 20.0314960479736px;">1,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-06', '%Y-%m-%d'),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-07', '%Y-%m-%d')</span></span><br />
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> );</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"></span></span><br />
<a name='more'></a><span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">CREATE PROCEDURE search (start DATE, end DATE)</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">BEGIN</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> DECLARE result VARCHAR(255);</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @result = '';</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @iterDate = start;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> label1: LOOP</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> IF @iterDate = start THEN</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @result = CONCAT(@result, ' SELECT * FROM bugs WHERE open_date <= DATE(\'',@iterDate,'\') AND close_date = DATE(\'',@iterDate,'\') UNION ALL');</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ELSEIF @iterDate = end THEN</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @result = CONCAT(@result, ' SELECT * FROM bugs WHERE open_date <= DATE(\'',@iterDate,'\') AND close_date >= DATE(\'',@iterDate,'\') UNION ALL');</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ELSE</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @result = CONCAT(@result, ' SELECT * FROM bugs WHERE open_date <= DATE(\'',@iterDate,'\') AND close_date = DATE(\'',@iterDate,'\') UNION ALL');</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> END IF;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @iterDate = DATE_ADD(@iterDate, INTERVAL 1 DAY);</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> IF @iterDate <= end THEN</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ITERATE label1;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> END IF;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> LEAVE label1;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> END LOOP label1;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> SET @result = LEFT(@result, LENGTH(@result)-LENGTH('UNION ALL'));</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> PREPARE stmt FROM @result;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> EXECUTE stmt;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">END//</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">CALL search(</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-01', '%Y-%m-%d'),</span></span><br />
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> STR_TO_DATE('2012-01-03', '%Y-%m-%d'));</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5o2XdJYgAxmdvB-cCzixjsANhtCVrtvU4X4vpgf4il5Qzn-0Ve7anF6K46SmaYeP4vJqvR5wynGkZd2_cGh6azjCONmY22cPgKpOeKnHzxRREB-mxigNJygJauWqd8mst3sSeJs0ltJe0/s1600/bugtraking+%25281%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5o2XdJYgAxmdvB-cCzixjsANhtCVrtvU4X4vpgf4il5Qzn-0Ve7anF6K46SmaYeP4vJqvR5wynGkZd2_cGh6azjCONmY22cPgKpOeKnHzxRREB-mxigNJygJauWqd8mst3sSeJs0ltJe0/s400/bugtraking+%25281%2529.png" width="400" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;">I may be wrong but hopefully I got this right. Feel free to comment or let me know your solutions.</span><br />
<br />paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-69775478017871907122015-10-15T07:22:00.003-07:002015-10-15T09:13:32.388-07:00MySQL - Function to Capitalize First Letter of a Word<span style="font-family: Trebuchet MS, sans-serif;">October 15, 2015 - I was bored so I went to play around with MySQL and solve some simple problem or exercise below to energize my playful mind.</span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Write a function to capitalize the first letter of
a word in a given string.</b></span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;">Example: initcap(UNITeD states Of AmERIca ) = United
States Of America</span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">CREATE TABLE names (name VARCHAR(250));</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">INSERT INTO names (name) VALUES</span></span><br />
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ("uNited states oF americA");</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"></span></span><br />
<a name='more'></a><span style="font-family: Trebuchet MS, sans-serif;"><b>Solution:</b></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><b><br /></b></span></span>
-- First word capitalize<br />
CREATE FUNCTION initcap(input VARCHAR(250))<br />
RETURNS VARCHAR(250) DETERMINISTIC<br />
BEGIN<br />
<br />
SET @inputCap = CONCAT(UCASE(LEFT(input, 1)), LCASE(SUBSTRING(input, 2)));<br />
SET @output = UCASE(LEFT(input, 1));<br />
SET @index=1;<br />
SET @previousChar = SUBSTRING(input, @index, 1);<br />
SET @currentChar = '';<br />
<br />
charLoop: LOOP<br />
SET @index = @index + 1;<br />
SET @currentChar = SUBSTRING(input, @index, 1);<br />
<br />
IF @previousChar = ' ' THEN<br />
SET @output = CONCAT(@output,UCASE(@currentChar));<br />
ELSE<br />
SET @output = CONCAT(@output,LCASE(@currentChar));<br />
END IF;<br />
SET @previousChar = @currentChar;<br />
<br />
IF (@index < LENGTH(input)) THEN<br />
ITERATE charLoop;<br />
END IF;<br />
LEAVE charLoop;<br />
END LOOP charLoop;<br />
<br />
<br />
RETURN @output;<br />
END//<br />
<br />
select initcap(name) from names;<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS0JtypL3ELx1VnkSwZpnHur0ewF5bAcfpyNj8IPRLrqFBU4jMh0Hc-jpm6AmC0wXVNgBO0v6vHyvpYFD3-NTvnpVInTHQROGZShEi_SdibEbXqQt7nmERyZYIMdqBbRKkJNrK_QZQQI8T/s1600/capitalize+%25281%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS0JtypL3ELx1VnkSwZpnHur0ewF5bAcfpyNj8IPRLrqFBU4jMh0Hc-jpm6AmC0wXVNgBO0v6vHyvpYFD3-NTvnpVInTHQROGZShEi_SdibEbXqQt7nmERyZYIMdqBbRKkJNrK_QZQQI8T/s400/capitalize+%25281%2529.png" width="400" /></a></div>
<br />
<br />
<span style="line-height: 0.53cm;"><span style="font-family: 'Trebuchet MS', sans-serif; line-height: normal;">I may be wrong but hopefully I got this right. Feel free to comment or let me know your solutions.</span><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-73541313455426341212015-10-15T07:06:00.004-07:002015-10-15T09:12:41.851-07:00MySQL - Rank Order by Votes<span style="font-family: Trebuchet MS, sans-serif;">October 15, 2015 - I was bored so I went to play around with MySQL and solve some simple problem or exercise below to energize my playful mind.</span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span>
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><b>Write a query to rank order the following table in MySQL by votes,
display the rank as one of the columns.</b></span></span><br />
<span style="line-height: 0.53cm;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span><span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">CREATE TABLE votes ( name CHAR(10), votes INT );</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">INSERT INTO votes VALUES</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ('Smith',10),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ('Jones',15),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ('White',20),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ('Black',40),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ('Green',50),</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> ('Brown',20);</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"></span></span><br />
<a name='more'></a><span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><b>Solution:</b></span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">SELECT</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">CASE</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> WHEN @prevRanking = votes THEN @curRanking</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"> WHEN @prevRanking := votes THEN @curRanking := @curRanking+1</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">END AS rank,name,votes</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">FROM votes, (SELECT @curRanking:=0,@prevRanking:=NULL) AS t</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;">ORDER BY votes desc;</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6UeI0N-KlAJCzALFy_NPmQbe-VMc90Zn-PVJAcwmUEXDRuCIlMH5Xhy8Sbv90hum7sREj_1E3AWKcDJ1iEA4aQ0rczsPIfCpOW54ARnEe9l_ROmLkAp18x3pC8zNFq9Yc-2S2tGRuJm3K/s1600/ranking+%25281%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6UeI0N-KlAJCzALFy_NPmQbe-VMc90Zn-PVJAcwmUEXDRuCIlMH5Xhy8Sbv90hum7sREj_1E3AWKcDJ1iEA4aQ0rczsPIfCpOW54ARnEe9l_ROmLkAp18x3pC8zNFq9Yc-2S2tGRuJm3K/s400/ranking+%25281%2529.png" width="400" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 20.0314960479736px;"><br /></span></span>
<span style="font-family: 'Trebuchet MS', sans-serif;">I may be wrong but hopefully I got this right. Feel free to comment or let me know your solutions.</span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-81766055748005767362015-10-14T22:38:00.001-07:002015-10-14T22:38:36.054-07:00Cagayan de Oro - Software Freedom Day 2015<span style="font-family: Verdana, sans-serif;">September 19, 2015 - A community organized event, Software Freedom Day, for the community in Cagayan de Oro City was held at Capitol University Laboratories.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">It has been a tradition that ITGx together with Capitol University to organize and celebrate SFD every year along with various walk-in guests and invited guests from other school organization. Farthest was guests from Ozamis City which is approximately 5 hours away from the venue.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">The goal of the event is to educate the public about the benefits of using high quality Free and Open Source Software (FOSS), Cagayan de Oro's Software Freedom Day celebration is filled with talks on various technologies from some of the leading developers in CdeO.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I had participated in the event as a resource speaker to talk about Play Framework fundamental and basics. Day after the event, I had a conversation with one of the audience and its good to hear that I am helping people learn to easily solve problems. Feels great.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Bellow was the schedule of events during that day and it was full of session everyone could learn.</span><br />
<br />
<table style="background-color: white; border-collapse: collapse; color: #444444; font-family: 'DejaVu Sans', 'Droid Sans', Verdana, sans-serif; font-size: 11.5200004577637px; margin: 0.5em auto;"><tbody>
<tr><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><div class="line862">
8:00AM - 8:45AM</div>
</td><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><div class="line862">
Registration and Sign up</div>
</td></tr>
<tr><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><span class="anchor" id="line-21"></span><div class="line862">
8:45AM - 9:20AM</div>
</td><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><div class="line862">
Opening program<br />Invocation by CS-SBO President<br />National Anthem<br /><br />Dr. Karen Joie Cuenca<br />IT Supervisor, CHED-REGION 10<br />Keynote Speech</div>
</td></tr>
<tr><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><span class="anchor" id="line-22"></span><div class="line862">
Morning Sessions</div>
</td><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><div class="line862">
9:30AM - 11:45AM</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-23"></span><div class="line862">
Virtual Reality<br />By Geoff Diaz and Edmund Madrid Salcedo Jr.<br />Edge Interactive<br />LAB A</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-24"></span><div class="line862">
Python Fundamentals<br />By ITG-<a class="nonexistent" href="http://wiki.softwarefreedomday.org/PyTsada" style="color: #ff0022; text-decoration: none;">PyTsada</a> with Arvin Vincent Simon from Innovuze<br />LAB B</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-25"></span><div class="line862">
Introduction to Play Framework for other Devs<br />By Paul Labis<br />Mangium Software<br />LAB C</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-26"></span><div class="line862">
Open Source <a class="nonexistent" href="http://wiki.softwarefreedomday.org/DevOps" style="color: #ff0022; text-decoration: none;">DevOps</a> Tools<br />By Romar Mayer Micabalo <a class="nonexistent" href="http://wiki.softwarefreedomday.org/SysAdmin" style="color: #ff0022; text-decoration: none;">SysAdmin</a>, Innovuze<br />LAB D</div>
</td></tr>
<tr><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><span class="anchor" id="line-27"></span><div class="line862">
Lunch Break</div>
</td><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"></td></tr>
<tr><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><span class="anchor" id="line-28"></span><div class="line862">
Afternoon Sessions</div>
</td><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><div class="line862">
1:30PM - 3:45PM</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-29"></span><div class="line862">
Introduction to Haskell<br />By JR Requiroso, <a class="nonexistent" href="http://wiki.softwarefreedomday.org/RedLemon" style="color: #ff0022; text-decoration: none;">RedLemon</a> Digital Media<br />LAB A</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-30"></span><div class="line862">
Python Flask<br />By ITG-<a class="nonexistent" href="http://wiki.softwarefreedomday.org/PyTsada" style="color: #ff0022; text-decoration: none;">PyTsada</a> with Romar Mayer Micabalo from Innovuze<br />LAB B</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-31"></span><div class="line862">
The IoT Stack: A Dissection: Arduino, Python, MQTT and everyTHING<br />By Aryan Limjap and Jay Ginete, Capitol University<br />LAB C</div>
</td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-32"></span><div class="line862">
PHP The Right Way<br />By Rudenyl Betonio, Innovuze<br />LAB D</div>
</td></tr>
<tr><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"><span class="anchor" id="line-33"></span><div class="line862">
3:45PM - 4:00PM</div>
</td><td style="border: 1px solid rgb(153, 153, 153); padding: 0.25em;"></td></tr>
<tr><td colspan="2" style="border: 1px solid rgb(153, 153, 153); padding: 0.25em; text-align: center;"><span class="anchor" id="line-34"></span><div class="line862">
Closing Ceremonies<br />Signing of event Plaque<br />Group picture taking</div>
</td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Hoping for next years Software Freedom Day.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-45620071311108171872015-10-14T22:03:00.000-07:002015-10-14T22:43:06.822-07:00Information Technology Group X - Balingasag Tech Talk<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif;">August 25, 2015 - A technology event was held in Misamis Oriental Institute of Science and Technology (MOIST) organized by host school in partnership with Information Technology Group X (ITGx). Supported by Google Developers Group - CDO, DevCon, Google Business Group and other companies locally like Mangium Software, Cleversoft and Innovuze Solutions.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif;">The event concluded successfully that is able to transfer useful knowledge on various technologies commonly used and practiced by developers, system administrators and DevOps. Most of the audience are college students and faculties members. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif;">It was a fun ride for about 1 hour and 30 minutes going to the venue from city proper. Effort was worth it specially when you hear audience saying they learn so much from the event that they can use for their projects. ITGx organized great and passionate pool of speakers with over 30+ years of total experience in technology industry. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Verdana, sans-serif;">Below is a picture giving ITGx token of appreciation to MOIST for hosting and organizing the event. Special thanks to <a href="https://www.facebook.com/FlexSambere">Felixberto S. Sambere</a> and <a href="https://www.facebook.com/tahir.aziz.7">Tahir Aziz</a> for a successful, fun filled out-of-town, first of its kind ITGx version of technology tech talk event</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3zZz2-rqwgo-y4MzWvm87pDbkazHE8_GcCdLIu_ztCVkazPrMwwcb9e1L18ZtGFpsb0RdiWJqAmamWHqOKjKacmElfRCsPp4vSMjKn0gewypuxDcjSwl0Zee1Ks5amC90uy7eMrnogfan/s1600/12022593_10208159104921367_682104921662792867_o.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: black; font-family: Verdana, sans-serif;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3zZz2-rqwgo-y4MzWvm87pDbkazHE8_GcCdLIu_ztCVkazPrMwwcb9e1L18ZtGFpsb0RdiWJqAmamWHqOKjKacmElfRCsPp4vSMjKn0gewypuxDcjSwl0Zee1Ks5amC90uy7eMrnogfan/s400/12022593_10208159104921367_682104921662792867_o.jpg" width="400" /></span></a></div>
<div style="text-align: center;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">I hope to go back there someday and do a talk on technologies I love to work on. Hopefully next year we do another one. :)</span></div>
<div>
<br /></div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0Cogon, Balingasag, Misamis Oriental, Philippines8.7515711235454212 124.778509140014658.749609623545421 124.77598764001465 8.7535326235454214 124.78103064001465tag:blogger.com,1999:blog-2699005904760025013.post-72377552445613216412015-07-15T10:06:00.001-07:002015-07-15T10:06:57.579-07:00Fix Inverted Camera on Ubuntu Linux<div style="font-family: Arial,Helvetica,sans-serif;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjM6dn4CV9c2Msas2dnHNhn01R_k-JdnUZy-1sfO7SICRRg425msK2dbRIJeFBEbI7biV-Tonl_npRwiJeL5HpLuKEdUcvzkII87E2c_P7yDsVWF9qdwpee7fS6Dxm8rH0DzdZy5mVnrU/s1600/green-bubblehead-webcam.jpg" imageanchor="1" rel="lightbox" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" title="Inverted camera"><img border="0" height="170" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjM6dn4CV9c2Msas2dnHNhn01R_k-JdnUZy-1sfO7SICRRg425msK2dbRIJeFBEbI7biV-Tonl_npRwiJeL5HpLuKEdUcvzkII87E2c_P7yDsVWF9qdwpee7fS6Dxm8rH0DzdZy5mVnrU/s200/green-bubblehead-webcam.jpg" width="154" /></a></div>
<span style="font-size: small;">I am running Lucid Lynx 64 bit OS version on my Asus i3 K52J Series laptop. Like everyone else, I like using Skype video/chat as well as Cheese camera for taking pictures and videos. Not until then when I had a problem using it.</span><br />
<span style="font-size: small;"><br />
</span><br />
<blockquote>
<span style="font-size: small;">NOTE: Not advisable to do "export LIBV4LCONTROL_FLAGS=3", LIBV4LCONTROL_FLAGS is for debugging purposes only. - by Hans De Goede(libv4l author and maintainer)</span></blockquote>
</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">I was so disappointed that my camera display was inverted! I tried reading several blogs and posting comments on Ubuntu forum threads online for days and but none of their solutions helped solved my problem. It could have been easily solved if only there was an option to invert my camera on Video4Linux Device Preference. Sadly, there was not! So, I decided to find a way to flip the camera by looking into export options on gtk-v4l(Video4Linux). </span><br />
<a name='more'></a></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">Below are the 2 things I did to solve my problem.</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">1. Add software source where libv4l-0 can be downloaded and install it by running the commands below on your terminal.</span><br />
<ul>
<li><span style="font-size: small;">echo -e "\n# libv4l PPA\ndeb http://ppa.launchpad.net/libv4l/ppa/ubuntu `lsb_release -c | awk '{print $2}'` main" | sudo tee -a /etc/apt/sources.list</span></li>
<li><span style="font-size: small;">sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com C3FFB4AA</span></li>
<li><span style="font-size: small;">sudo apt-get update</span></li>
<li><span style="font-size: small;">sudo apt-get install libv4l-0</span></li>
</ul>
</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">2. Start cheese or skype from your terminal. (Note: The value of 3 on LIBV4LCONTROL_FLAGS flips the image both vertically and horizontally.)</span></div>
<ul style="font-family: Arial,Helvetica,sans-serif;">
<li><span style="font-size: small;">export LIBV4LCONTROL_FLAGS=3 && <b>cheese </b></span></li>
<li><span style="font-size: small;">export LIBV4LCONTROL_FLAGS=3 && LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so <b>skype</b></span></li>
</ul>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">Alternatively, you can create a shortcut(custom application launcher) on your menu or on one of your panels. </span></div>
<ul style="font-family: Arial,Helvetica,sans-serif;">
<li><span style="font-size: small;">Download <a href="http://www.weebly.com/uploads/3/9/8/1/3981509/cheese.sh"><b>skype</b></a> and <a href="http://www.weebly.com/uploads/3/9/8/1/3981509/skype.sh"><b>cheese</b></a> scripts. </span></li>
<li><span style="font-size: small;">Add custom application launcher on panel and point command to respective bash scripts.</span></li>
<li><span style="font-size: small;">Click icon and start using the applications normally!</span></li>
</ul>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">If your having problem on your sound device on Skype, take a look on my previous article on <a href="http://techieboycdo.blogspot.com/2010/08/fix-asus-k52j-sound-or-speaker-problem.html">fixing sound device</a>. Alright then, thats all I did folks! Hope this helps. Have a good one. </span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-50102334727314071992015-07-10T04:23:00.000-07:002015-07-10T04:23:53.863-07:00Backup or Restore PostgreSQL Database<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOAG-cyVlj5-4_AVUoCBfA7hyj6-Dv1d6-Y_Y8q5xEdncqNpwgWoJ6RRHQT020z0fU7SjUF0GmFprYd-pujFcixcSd_q-Y4b2DLwrKCE3Pm2H0zsHy2Q2BZRE7NErV3SEst2kWzAmz5FE/s1600/pgsql-logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOAG-cyVlj5-4_AVUoCBfA7hyj6-Dv1d6-Y_Y8q5xEdncqNpwgWoJ6RRHQT020z0fU7SjUF0GmFprYd-pujFcixcSd_q-Y4b2DLwrKCE3Pm2H0zsHy2Q2BZRE7NErV3SEst2kWzAmz5FE/s1600/pgsql-logo.png" /></a></div>
<div style="text-align: justify;">
There is an easy way to create backup file and restore your current PostgreSQL database using the Linux terminal. I am not sure though if this is the easiest way. <br />
<br />
As of the moment I am writing this article, I used the following command to backup and restore my database. </div>
<div>
<br /></div>
<div>
Using <a href="http://www.postgresql.org/docs/current/static/app-pgdump.html">pg_dump</a> and <a href="http://www.postgresql.org/docs/current/static/app-psql.html">psql</a> will make your life easier. Below are the terminal command I use to backup and restore my database.</div>
<div>
<ul>
<li>Backup : <b>pg_dump</b> -U {user_name} {database_name} -f {backup_file_name}</li>
<li>Restore : <b>psql</b> -U {user_name} -d {database_name} -f {backup_file_name}</li>
</ul>
<div>
If you are getting an error:<br />
<a name='more'></a></div>
<blockquote>
psql: FATAL: Ident authentication failed for user "username"...</blockquote>
<div>
You then need to locate file <b>pg_hba.conf</b> and add or change if already existing to look something like below:</div>
<div>
<br /></div>
<div>
<span class="Apple-style-span" style="background-color: white; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; line-height: 22px;"></span><br />
<pre style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(221, 221, 221); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(221, 221, 221); border-top-style: solid; border-top-width: 1px; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em; margin-bottom: 1.833em; overflow-x: auto; overflow-y: auto; padding-bottom: 0.667em; padding-left: 0.917em; padding-right: 0.917em; padding-top: 0.667em;"><span class="Apple-style-span" style="background-color: white; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; line-height: 22px;">local all all trust
host all 127.0.0.1/32 trust</span></pre>
<span class="Apple-style-span" style="background-color: white; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; line-height: 22px;">
</span></div>
<div>
<div style="text-align: justify;">
<div style="text-align: left;">
By the way, to locate file on your Ubuntu... Just run command "<b>locate pg_hba.conf</b>" on your terminal.</div>
</div>
</div>
<div>
<div style="text-align: justify;">
<div style="text-align: left;">
After which, restart PostgreSQL database by running "<b>sudo /etc/init.d/postgresql_version restart</b>". Hopefully the error should already be fixed.</div>
</div>
</div>
<div>
<div style="text-align: justify;">
<br /></div>
</div>
<div>
<div style="text-align: justify;">
There are lots of articles online that you can read to backup and restore you database. I hope this article helps you in one way or another.</div>
</div>
<div>
<div style="text-align: justify;">
<br /></div>
</div>
<div>
<div style="text-align: justify;">
I give all credits to <a href="http://www.thegeekstuff.com/2009/01/how-to-backup-and-restore-postgres-database-using-pg_dump-and-psql/">www.thegeekstuff.com</a> for doing a good job on explaining how you can use pg_dump and psql to backup your PostgreSQL database. </div>
</div>
</div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-27670660143574722312015-06-13T22:13:00.000-07:002015-06-13T22:13:06.817-07:00Encrypt and decrypt your files in Ubuntu using ccrypt<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">ccrypt is a utility for encrypting and decrypting files and streams. It was based on Rijndael cipher, which was chosen candidate by U.S. government's for Advance Encryption Standard. This cipher is believed to provide a very strong security.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">1. Install CCrypt from repo</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">sudo apt-get install ccrypt</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">2. To encrypt a file, use one of the following command,</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>ccrypt -e file_name</b> or <b>ccencrypt file_name</b></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">3. It will prompt you for Encryption Phrase aka Password, enter it. for example,</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">ccrypt -e sample.text </span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Enter encryption key: your_key </span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Enter encryption key: (repeat) your_key </span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Note: Don't forget the encryption phrase, there is no way to get back the original file without it.</span><br />
<a name='more'></a><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To decrypt file/files, use one of the following commands:</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>ccrypt -d file_name</b> or <b>ccdecrypt</b> <b>file_name</b> </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">It will prompt you for encryption phrase, enter it.
Original file is brought back!</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To change the encryption key, <b>ccrypt -x file_name</b></span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I guess that is all there is to share. Good luck!</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br /></span>paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-72994533277512309912015-06-13T21:45:00.000-07:002015-06-13T21:45:07.505-07:00Properties File with Arguments or Pameters<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">The goal on this tutorial is to be able to format a value on a properties file given its parameter or arguments. It is best describe as passing value as a parameter and inserting those values on the string retrieved from the properties file.</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">To better understand what I'm doing, read and understand my example code below.</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">Property File Sample</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><code>message.welcome= Welcome {0} to {1}!<br />
message.thank= Thank you for you visit {0}.</code></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"></span><br />
<a name='more'></a><span style="font-size: small;">Java Code using ResourceBundle and MessageFormat</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><code>ResourceBundle resBundle = new ResourceBundle("path to property file"); <br />
String welcomeText=resBundle.getString("message.welcome");<br />
MessageFormat msgFormatter = new MessageFormat(welcomeText);<br />
<br />
// Create the dynamic args you want to replace<br />
Object[] messageArguments = {"Techie boy","Philippines"}; <br />
<br />
String finalText= msgFormatter.format(messageArguments);</code></span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;"><br />
</span></div>
<div style="font-family: Arial,Helvetica,sans-serif;">
<span style="font-size: small;">The finalText will result to "Welcome Techie boy to Philippines!"</span></div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-4501789077284031932015-06-05T12:23:00.001-07:002015-06-05T12:23:46.973-07:00Quest for New Challenging Project beyond Social MediaIt has been quite a journey working with a social media focused company and learned a lot of interesting frameworks and libraries in developing projects and modules internally and the products for years of work. Its nearly end of my contract and I guess its already time for a change so I started looking for other opportunities just recently.<br />
<br />
These days, there are so many job sites and mostly these platforms are free for all. Legit though I think that they seem to skip having to screen job applicants or companies for quality. And quality to me means a lot. Who knows? Company or person posting jobs on those job sites may be fake and could just use applicants email as receivers of spam advertising. Or worse, sell your resume somewhere. I maybe wrong but the point I wanna stress out is how confident you are with your trust.<br />
<br />
So I scanned these sites and one of which I think is most formidable and promising is <a href="http://www.toptal.com/" target="_blank"><b>Toptal</b></a>. Its quite a quality site having employers and resources that are hand-picked and filtered. This is beyond services of any other job sites and first impression is awesomeness. They have installed a screening process to insure they get only the best gets the opportunity. They claim only 3% elite developers gets in.<br />
<br />
That given, I am determined to accept the challenge to become part if their growing family of elite developers.paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-10570952324238528262015-05-19T09:13:00.003-07:002015-05-19T09:53:43.848-07:00Separate Configuration for Play Framework / Play2 production, testing and development environmentWorking on Play Framework configuration is easy. In this article, I'll walk you through simple implementation where you are able to create a generic application.conf and a dedicated application.conf for each environment.<br />
<br />
<br />
Objective: To be able to easily manage your Play2 application configuration separately for production, testing and development.<br />
<br />
Solution: Override GlobalSettings onLoadConfig to point to a commong configuration and a fallback configuration specific for your current environment. Your code should look like below.<br />
<a name='more'></a><br />
<br />
<span style="font-family: monospace;"> @Override</span><br />
<span style="font-family: monospace;"> public Configuration onLoadConfig(Configuration configuration, File file, ClassLoader classLoader, Mode mode) {</span><br />
<span style="font-family: monospace;"><br /></span>
<span style="font-family: monospace;"> String path = String.format("%s/conf/%s/application.conf", </span><span style="font-family: monospace;">file.getPath()</span><span style="font-family: monospace;">, mode.name().toLowerCase());</span><br />
<span style="font-family: monospace;"><br /></span>
<span style="font-family: monospace;"> Logger.info("Fallback configuration: {}", path);</span><br />
<span style="font-family: monospace;"><br /></span>
<span style="font-family: monospace;"> Config envConfig = ConfigFactory.parseFile(new File(path));</span><br />
<span style="font-family: monospace;"> Config baseConfig = configuration.getWrappedConfiguration().underlying();</span><br />
<span style="font-family: monospace;"><br /></span>
<span style="font-family: monospace;"> return new Configuration(baseConfig.withFallback(envConfig));</span><br />
<span style="font-family: monospace;"> }</span><br />
<br />
And finally, you should have setup your configurations under conf/ on your project.<br />
<br />
You should have something like below.<br />
<br />
<br />
conf/application.conf --> configurations common for all environment<br />
conf/dev/application.conf --> configurations for development environment<br />
conf/test/application.conf --> configurations for testing environment<br />
conf/prod/application.conf --> configurations for production environment<br />
<br />
That is all there is to do. This may not be perfect solution but hopefully you'll find this useful.<br />
<br />
Leave a comment below for your questions or thoughts.<br />
<br />
Thanks!<br />
<br />
<br />paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-68261701171778592382015-05-07T09:53:00.002-07:002015-05-07T09:54:01.739-07:00Embedded Jetty in Spring MVC, IoC/DI<div style="font-family: Arial, Helvetica, sans-serif;">
<span style="font-size: small;"><br class="Apple-interchange-newline" />I was trying to configure embedded jetty in a </span><span style="font-size: small;">spring application that implements MVC(Model View Controller). I want to utilize single spring applicationContext xml file </span>for IoC(Inversion of Control) and DI(Dependency Injection) on dispatcher servlets.<br />
<br />
The goal is to be able to use or reference beans configured/located on already been loaded spring application context. Read and understand my resolution below.<br />
<a name='more'></a></div>
<br />
<div style="font-family: Arial, Helvetica, sans-serif;">
This is what my main method look like:</div>
<code>LOG.info("Application starting");<br />_applicationContext = new ClassPathXmlApplicationContext(_resourceLocations);<br /><br />_webServer = new Server();<br />SelectChannelConnector connector = new SelectChannelConnector();<br />connector.setHost("localhost");<br />connector.setPort(8080);<br />_webServer.addConnector(connector);<br /><br />WebAppContext webAppContext = new WebAppContext(_webServer, "path to web app folder", "/");<br /><br />GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();<br />webApplicationContext.setServletContext(webAppContext.getServletContext());<br />webApplicationContext.setParent(_applicationContext);<br /><br />webAppContext.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);<br />webApplicationContext.refresh();<br /><br />ServletHandler servletHandler = new ServletHandler();<br /><br />ServletHolder servletHolder = new ServletHolder(new DispatcherServlet());<br />servletHolder.setName("dispatcher");<br />servletHandler.addServlet(servletHolder);<br /><br />ServletMapping servletMapping = new ServletMapping();<br />servletMapping.setServletName(servletHolder.getName());<br />servletMapping.setPathSpec("*.htm");<br />servletHandler.addServletMapping(servletMapping);<br /><br />webAppContext.setServletHandler(servletHandler);<br />_webServer.addHandler(webAppContext);<br /><br />RequestLogHandler logHandler = new RequestLogHandler();<br />NCSARequestLog ncsaLog = new NCSARequestLog();<br />ncsaLog.setExtended(true);<br />ncsaLog.setFilename("logs/jetty-yyyy_mm_dd.log");<br />logHandler.setRequestLog(ncsaLog);<br />_webServer.addHandler(logHandler);<br /><br />LOG.info("Starting main application context");<br />_applicationContext.start();<br /><br />LOG.info("Starting Jetty Server");<br /><br />try {<br />_webServer.start();<br />} catch (Exception e) {<br />// TODO Auto-generated catch block<br />e.printStackTrace();<br />}<br /><br />LOG.info("Application started");<br />return null;</code><br />
<div style="font-family: Arial, Helvetica, sans-serif; text-align: justify;">
The idea is that DispatcherServlet's context is child context of <b>GenericWebApplicationContext</b> which in turn is a child of <b>ClassPathXmlApplicationContext</b>. Explicitly invoking setParent() gives you the access to all beans from the web application context.</div>
<div style="font-family: Arial, Helvetica, sans-serif; text-align: justify;">
<br /></div>
<div style="font-family: Arial, Helvetica, sans-serif; text-align: justify;">
Hope this helps. Feel free to leave your comment or suggestions.</div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0tag:blogger.com,1999:blog-2699005904760025013.post-24583515183230824972014-12-29T22:30:00.002-08:002014-12-29T22:38:06.804-08:00Java Garbage Collection is Not Instant<span style="font-family: Verdana, sans-serif;">So over the weekend I had some experiment with Java GC and decided to write something about it. I was just mingling around to prove that just because a Java object or variable is eligible for garbage collection does not mean it gets collected right away.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">That momentary moment becomes a window of opportunity for a hacker/attacker to sniff into maybe a sensitive data from your application through a heap memory dump. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">To prove this, I created a simple console application for this experimentation.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">1. Create Java program:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;">public class HelloWorld {</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> private static void readData() {</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> System.out.println("Enter password here : ");</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> Scanner scanIn = new Scanner(System.in);</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> char[] sesitiveData = scanIn.nextLine().toCharArray();</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> scanIn.close();</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> }</b></span><br />
<b><span style="background-color: black; color: white;"><span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"> public static void main(String[] args) throws Exception {</span></span></b><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> readData();</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> Thread.sleep(1000 * 3600);</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"> }</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;">}</b></span><br />
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;"><br /></b></span>
<br />
<a name='more'></a><br />
<span style="font-family: Verdana, sans-serif;">2. Compile: javac HelloWorld.java</span><br />
<span style="font-family: Verdana, sans-serif;">3. Run: java HelloWorld</span><br />
<span style="font-family: Verdana, sans-serif;">4. Enter any data (for example 'hacked'), hit enter</span><br />
<span style="font-family: Verdana, sans-serif;">5. Find the PID: '<b style="background-color: black;"><span style="color: white;">ps -efa | grep java</span></b>' or you could do it in other way you prefer to</span><br />
<span style="font-family: Verdana, sans-serif;">7. Create a heap dump: <b style="background-color: black;"><span style="color: white;">jmap -dump:format=b, file=myapp.bin 100</span></b> (given that 100 is the application PID)</span><br />
<span style="font-family: Verdana, sans-serif;">8. Open <a href="http://visualvm.java.net/" target="_blank">VisualVM</a> profiler, go to File/Load and select the heap dump you created earlier.</span><br />
<span style="font-family: Verdana, sans-serif;">9. Next go to the OQL console and run the query bellow:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="color: white; font-family: Verdana, sans-serif;"><b style="background-color: black;">select a from char[] a where a.length == 6 && a[0] == 'h'</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">As you can see below, the query result to the screenshot. The array containing data you provided on console was found to think that it is already not referenced and unused, and the object was due for garbage collection. This proves that even objects referenced locally stays on heap until garbage collected.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN67ZLn7b57v901mgtwCqRByt8gc6QQqtoeydUeLG97pqL410Ggxsetpz39Kpnv4akts2oRpyQEfogGOy7ZjMr19eDQJyek5f6zxfAm75EjBAFe56nJiaq64CIWZgMRQiRkn4k3BrcvmvY/s1600/Screenshot+from+2014+12+30+14+13+37.png++1920%C3%971080+.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN67ZLn7b57v901mgtwCqRByt8gc6QQqtoeydUeLG97pqL410Ggxsetpz39Kpnv4akts2oRpyQEfogGOy7ZjMr19eDQJyek5f6zxfAm75EjBAFe56nJiaq64CIWZgMRQiRkn4k3BrcvmvY/s1600/Screenshot+from+2014+12+30+14+13+37.png++1920%C3%971080+.png" height="237" width="320" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">To get that data out of heap, you just have to null-out the declared array variable and try the procedure again. The array containing your data should disappear. </span><br />
<span style="font-family: Verdana, sans-serif;"><br />Important to note here is after using even a locally referenced objects, you should manually zero the returned character array after processing to minimize the lifetime of sensitive data in memory.</span><br />
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">I hope this article is helpful. Enjoy!</span><span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;"><br /></span>
</div>
paulhttp://www.blogger.com/profile/14361976311935199737noreply@blogger.com0