P_W999

Because life has no try-catch


Leave a comment

javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.

Last week, completely out of the blue I got faced with the following Soap exception:

 

2015-05-21 14:33:38,649 ERROR http-apr-8080-exec-4 [xxx.web.upload.generic.ExceptionHandler] Soap error
javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
 at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
 at com.sun.proxy.$Proxy231.geefExcelLijst(Unknown Source)
 at xxx.web.upload.controller.UploadController.downloadBestand(UploadController.java:170)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at xxx.web.beheer.shared.util.CspFilter.doFilter(CspFilter.java:50)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
 at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
 at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at xxx.security.openam.spring.security.OpenAMSSOLogoutFilter.doFilter(OpenAMSSOLogoutFilter.java:69)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
 at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
 at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
 at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
 at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
 at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
 at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
 at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
 at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
 at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
 at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:105)
 at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
 at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
 at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:771)
 at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1604)
 at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1489)
 at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1397)
 at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
 at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:644)
 at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
 at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:519)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:352)
 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:304)
 at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
 at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
 ... 72 more

I didn’t matter whether I ran my calls through Soap-UI or through the application, I would always face this error. No clear solutions were available on the internet, except for a bunch of things you could try.

Eventually I started debugging my code again but instead of stopping once my webservice method returned, I kept going deeper, passing through a lot of unknown (decompiled) code untill I finally hit on a caught exception. It turned out that a newly added advice would convert the result to a JSON message for audit logging and this particular conversion would result in a StackOverflowException when the result contained binary data (through a javax.activation.DataHandler object).

So if you happen to have this error, you might also want to check out your aspects ;)


1 Comment

Simple Angular.JS 1.3 directive for Bootstrap tooltip

This is a very simple Angular.js (1.3) directive to add a Bootstrap 3 tooltip to any component.

angular.module('angularBootstrapTooltipApp')
  .directive('angularTooltip', function () {
    return {
      restrict: 'A',
      replace: false,
      scope: {
        tooltipPlacement: '=?',
        tooltip: '='
      },
      compile: function compile( tElement, tAttributes ) {
        return function postLink( scope, element, attributes, controller ) {
          if (scope.tooltip !== '') {
            element.attr('data-toggle', 'tooltip');
            element.attr('data-placement', scope.tooltipPlacement || 'top');
            element.attr('title', scope.tooltip);
            element.tooltip();  
          }
          
          scope.$watch('tooltip', function(newVal) {
            if (!element.attr('data-toggle')) {
              element.attr('data-toggle', 'tooltip');
              element.attr('data-placement', scope.tooltipPlacement || 'top');
              element.attr('title', scope.tooltip);
              element.tooltip();  
            }
            element.attr('title', newVal);
            element.attr('data-original-title', newVal);
          });
        };
      }
    };
  });

A simple example:

<button type="button" 
    class="btn btn-default" 
    angular-tooltip
    tooltip-placement="bottom"
    tooltip="title">
{{title}}
</button>
<input type="text" ng-model="title"></input>

Whatever you type, the tooltip will always be up to date.
Screenshot from 2015-05-05 19:41:37

Comes with no guarantee, but feel free to use it wherever you need it.


Leave a comment

J-ExifTool v0.0.9

Today I’ve released version 0.0.9 of J-ExifTool. This release doesn’t add new features, but it’s more reliable so I highly suggest the upgrade:

  • Maven support ! It’s not in a public repository (yet), but it’s one step closer to using J-ExifTool in a maven project ;)
  • Buffers are more reliable
  • Some tests are re-written

The new jar can be downloaded from BitBucket.

For the record only: v0.0.9 is commit a780161.


Leave a comment

J-ExifTool v0.0.8

Today I’ve released version 0.0.8 of J-ExifTool. This release adds new functionalities and provides some bug fixes:

  • #8: Delete all exif tags
  • #12: extract thumnail image
  • #15: it’s now possible to read exiftool path from environment variable
  • Improved reading out the command line buffer (no more lost/split/incorrect values, tests are more stable now)

Since release v0.0.5 you’ll need the Apache Commons Exec library in your classpath. I’ve added a new lib folder on BitBucket which includes this new library or you can download the new library from Apache.

The new jar can be downloaded from BitBucket.

For the record only: v0.0.8 is commit 2f4414f.


Leave a comment

My IBM DB2 Cheat Sheet

This is a set of DB2 snippets I often used at work. I’m glad to share them with you.

Generate GRANT statements for a new DB2 user with name MYUSER user on all tables of a schema named MYSCHEMA:

select 'GRANT SELECT ON TABLE ' || TRIM(tabschema) || '.' || TRIM(tabname) || ' TO USER MYUSER @' from syscat.tables where tabschema = 'MYSCHEMA'
UNION
select 'GRANT INSERT ON TABLE ' || TRIM(tabschema) || '.' || TRIM(tabname) || ' TO USER MYUSER @' from syscat.tables where tabschema = 'MYSCHEMA'
UNION
select 'GRANT UPDATE ON TABLE ' || TRIM(tabschema) || '.' || TRIM(tabname) || ' TO USER MYUSER @' from syscat.tables where tabschema = 'MYSCHEMA' @

The following stored procedure will automatically generate and execute the grant statements

CREATE OR REPLACE PROCEDURE MYSCHEMA.GRANT_ME_SOME (IN SCHEMANAME VARCHAR(128), IN USRNME VARCHAR(128))
       DYNAMIC RESULT SETS 1
       MODIFIES SQL DATA
P1: BEGIN
		DECLARE q VARCHAR(1024);
		DECLARE AT_END SMALLINT DEFAULT 0 ;
		DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000' ;
		
		DECLARE CUR CURSOR WITH HOLD FOR 
		select 'GRANT SELECT ON TABLE ' || TRIM(tabschema) || '.' || TRIM(tabname) || ' TO USER ' || USRNME AS KWERIE from syscat.tables where tabschema = SCHEMANAME
		UNION
		select 'GRANT INSERT ON TABLE ' || TRIM(tabschema) || '.' || TRIM(tabname) || ' TO USER ' || USRNME  AS KWERIE from syscat.tables where tabschema = SCHEMANAME
		UNION
		select 'GRANT UPDATE ON TABLE ' || TRIM(tabschema) || '.' || TRIM(tabname) || ' TO USER ' || USRNME  AS KWERIE from syscat.tables where tabschema = SCHEMANAME; 
	
		DECLARE CONTINUE HANDLER FOR NOT_FOUND SET AT_END = 1 ;
		OPEN CUR;
		
		UPDATE_LOOP : LOOP
		
		FETCH CUR INTO q;
		IF AT_END <> 0 THEN
	        LEAVE UPDATE_LOOP ;
	    END IF ;
		
		EXECUTE IMMEDIATE q;
		
		END LOOP;
END P1;

Generate ‘reorg index’ and and ‘reorg columns’ statements for all tables of a schema MYSCHEMA

select 'CALL SYSPROC.ADMIN_CMD(''RUNSTATS ON TABLE ' ||TRIM(tabschema)||'.'||TRIM(tabname)||' FOR DETAILED INDEX ALL '')@' from syscat.tables where tabschema='MYSCHEMA' and type='T' 
UNION
select 'CALL SYSPROC.ADMIN_CMD(''RUNSTATS ON TABLE ' ||TRIM(tabschema)||'.'||TRIM(tabname)||' ON ALL COLUMNS'')@' from syscat.tables where tabschema='MYSCHEMA' and type='T' @

Generate reorg table statements for all tables of a schema MYSCHEMA

select 'CALL SYSPROC.ADMIN_CMD(''REORG TABLE '||TRIM(tabschema)||'.'||TRIM(tabname)||''') @' from syscat.tables where tabschema='MYSCHEMA' and type='T'

Find all inactive tables on your database

SELECT COALESCE(
 'SET INTEGRITY FOR  "' || TRIM(TABSCHEMA) || '"."' || TRIM(TABNAME) || 
  '"  IMMEDIATE CHECKED @' , '')
FROM

 TABLE
 ( SELECT TABSCHEMA, TABNAME
 FROM SYSCAT.TABLES
 WHERE (CONST_CHECKED LIKE '%N%'
 OR STATUS = 'C')
 UNION

 SELECT a.REFTABSCHEMA,a.REFTABNAME
 FROM SYSCAT.REFERENCES a,SYSCAT.TABLES b
 WHERE (a.TABSCHEMA, a.TABNAME) IN
 (SELECT TABSCHEMA, TABNAME
 FROM SYSCAT.TABLES
 WHERE (CONST_CHECKED LIKE '%N%'
 OR STATUS = 'C'))
 AND a.REFTABSCHEMA = b.TABSCHEMA
 AND a.REFTABNAME = b.TABNAME
 AND (b.CONST_CHECKED LIKE '%N%'
 OR b.STATUS = 'C')

 ) AS TAB( TABSCHEMA, TABNAME )
ORDER BY TABSCHEMA
FETCH FIRST 50 ROWS ONLY
OPTIMIZE FOR 1 ROW

Quickly unload a table (sets your table in an invalid state). Works from CLI only

db2 LOAD FROM /dev/null of del REPLACE INTO MYSCHEMA.MYTABLE

An example of a DELETE WITH statement using the SELECT FROM OLD TABLE structure. I previously covered this statement.

WITH 
	DOCLINK(ID) AS ( SELECT ID FROM OLD TABLE (
			DELETE FROM MYSCHEMA.MYTABLE1 WHERE CODE = 'XYZ'
		)
	), 
	DOCU(ID) AS (SELECT ID FROM OLD TABLE (
			DELETE FROM MYSCHEMA.MYTABLE2 WHERE DOC_ID IN (SELECT ID FROM DOCLINK)
		)
	)	
	SELECT COUNT FROM MYSCHEMA.MYTABLE1 WHERE CODE = 'XYZ'
 @

An example of a MERGE statement. The field MYTABLE.JAAR will be updated with the value of the matching field in MYTABLE2.JAAR. It’s what you would do with UPDATE MYTABLE.JAAR = (SELECT JAAR FROM MYTABLE2 WHERE MYTABLE.VELD_ID = MYTABLE.ID) if it were a valid statement.

MERGE INTO MYSCHEMA.MYTABLE VELD 
	USING (
		select DISTINCT V.ID AS VELD_ID, T.JAAR AS JAAR 
		 from MYSCHEMA.MYTABLE2 T, MYSCHEMA.MYTABLE3 V
                 WHERE    V.ID = T.V_ID
			AND V.TYPE_ID IN (  100000,   100065,   100130)
			AND T.JAAR IS NOT NULL
	) AS VELD_TO_UPDATE
	ON VELD_TO_UPDATE.VELD_ID = VELD.ID
	WHEN MATCHED THEN UPDATE SET VELD.JAAR = VELD_TO_UPDATE.JAAR 
	@

A simple WITH statements

WITH IDS(FRST, SCND, CNT) AS (
	SELECT MIN(ID), MAX(ID), COUNT(ID) FROM MYSCHEMA.MYTABLE
		WHERE ID > 105220
		GROUP BY EXT_ID, INT_ID
		HAVING COUNT(ID) > 1
) SELECT ID, REF FROM MYSCHEMA.MYTABLE2 WHERE
	IN in (SELECT FRST FROM IDS) 
	OR ID IN (SELECT SCND FROM IDS)
	ORDER BY REF
	FOR READ ONLY @

List aggregation (LISTAGG)

SELECT LISTAGG(REF, ', ') WITHIN GROUP(ORDER BY ID) 
   FROM MYSCHEMA.MYTABLE GROUP BY REF_PREFIX

Drop a schema (CLI)

db2 "CALL SYSPROC.ADMIN_DROP_SCHEMA('MYSCHEMA', NULL, 
 'DELETESCHEMA', 'ERR_DEL')"

Copy a schema (CLI)

db2 "CALL SYSPROC.ADMIN_COPY_SCHEMA('MYSCHEMA', 'MYNEWSCHEMA', 
 'COPY', null,  null, null, 'ERRORSCHEMA', 'ERRORTAB') "

DB2Advisor on schema MYSCHEMA (CLI) using an input file YOUR_QUERIES (you can also pass a password separately with -x)

db2advis -d MY_DB -t 30 -m IMP -noxml -i YOUR_QUERIES.SQL 
 -a USERNAME/PASSWORD -o OUTPUT.OUT -n MYSCHEMA -q MYSCHEMA

Create explain tables in your scherma.

CALL SYSPROC.SYSINSTALLOBJECTS('EXPLAIN', 'C', CAST (NULL AS VARCHAR(128)), 
 CAST ('MYUSER' AS VARCHAR(128)))


2 Comments

Babun: A touch of Linux in Windows aka A Cygwin that actually works

As a consultant working for a large firm I’m blessed with a Windows laptop and Windows desktop to do all my Java development. Lately I really started to miss some of the awesome stuff Linux has to offer and luck was on my side when I stumbled across Babun.

Babun is nothing more than a pre-configured Cygwin environment, though that doesn’t reflect how awesome it actually is. It’s the first time that I have a fully functioning Cygwin environment which requires no configuration at all and which I feel comfortable enough with to use on a daily base.

Babun screenshot

Babun screenshot

I didn’t like the default pastel color theme so I made the colors a bit harsher by changing the values in C:\Users\{you}\.babun\cygwin\etc\minttyrc
This is my current color configuration:

BoldAsFont=no
FontHeight=10
ForegroundColour=208,208,208
BackgroundColour=28,28,28
CursorColour=255,175,0
IMECursorColour=128,224,160
Black=12,12,12
BoldBlack=10,10,10
Red=245,135,135
BoldRed=253,135,135
Green=175,245,135
BoldGreen=175,243,135
Yellow=247,247,175
BoldYellow=255,255,175
Blue=135,175,245
BoldBlue=135,175,253
Magenta=215,175,215
BoldMagenta=223,175,223
Cyan=175,215,215
BoldCyan=175,223,223
White=250,250,250
BoldWhite=255,255,255
Transparency=off
OpaqueWhenFocused=no
CursorType=line
CursorBlinks=yes
FontSmoothing=full
Locale=en_US
Charset=UTF-8
ScrollbackLines=99000
ScrollMod=shift
PgUpDnScroll=yes
Term=xterm-256color
CopyAsRTF=no
RightClickAction=paste

For the Solarized fans there’s already a light and dark configuration file available on the world-wide web.

Another must-have is the zsh-syntax-highlighting plugin:

cd ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git

and editing the ~/.zshrc file with vim is all it takes to get syntax highlighting

plugins=(svn zsh-syntax-highlighting)
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) 

To be continued


Leave a comment

Github top 10 projects: swear count

After my yesterday’s post about the swear count script, I got a bit bored and decided to pull the top 10 projects on Github and get a swear count on those projects. Turns out these people are very patient :) .

Github top 10 projects - Swear Count

Github top 10 projects – Swear Count

I slightly tweaked the swearcount script so it would match the words if they were prefixed with a space ‘ ‘, a double forward slash ‘//’ or a comma ‘,’.
It will not use a suffix anymore, because it would exclude nasty words at the end of a line or words followed by a dot ‘.’.

 

If you’re interested: this is the tweaked swearcount script:

#!/bin/bash
# P_W999 - 2013 - This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
# http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
# This script comes as-is, with no guarantees or warranties and it is used at own risk.
# https://pw999.wordpress.com
# v0.1 - 2014-04-30
# * Initial release
# Small script based on http://www.vidarholen.net/contents/wordcount/ (Vidar Holen) to calculate the number of swears (and some other words) that can be found in your source code.
# The script takes a single parameter; the folder where your source code is located. So for example ./swearcount.sh ./trunk will lookup all nasty words in the trunk folder and subfolder.
# The script will look for exact matches with spaces before and after the word (otherwise 'fix' will also match 'prefix' )
 
# Check input
SRCPATH="$1"
if [[ "$SRCPATH" == "" ]] ; then
	    echo "You must pass the source code folder as first parameter"
	        exit 1
	fi
	# Define paths to ignore
	IGNORES='branch\|tag\|target\|generated'
#	echo "Script will ignore files with following patterns $IGNORES" | sed 's/\\|/, /g'
	 
	 
	# Magic
	find $SRCPATH -type f -print0 | xargs -0 -n 1 | grep -v -e $IGNORES | xargs cat | awk '
	        BEGIN {
			lines=0;
			w="fuck shit love piss fire bastard crap goto bullshit xxx todo fixme temporary bastard bug fix";			
			#    print "Looking for words: " w
			n=split(w,t," ");
			for(i=1; i<=n; i++) {
				c[t[i]]=0;
			}
		}
		{
			lines++;
			for(k in c) {
				a=0;
				a2=0;
				a3=0;
				a4=0;
				a5=0;
				f=tolower($0);
				do {
					a=index(f," " k);
					a2=index(f,"," k);
				        
				        a4=index(f, "//" k); 	
					
					if(a!=0 || a2!=0 || a3!=0 || a4!=0 || a5!=0) {
					c[k]++;
					# print the lines found
					gsub(/^[ \t]+/, "", $0);
					# print k ": " $0
				}
				else break;
				f=substr(f,a+length(k));
				} while(1);
			}
		}
		# Print stats
		END {
			print "lines " w;
			printf "%d ",lines;
			for(i=1; i<=n; i++) printf "%d ",c[t[i]];
			printf "\n";
		}'

And this is the script I wrote to get the results:

#!/bin/bash
# P_W999 - 2013 - This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
# http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
# This script comes as-is, with no guarantees or warranties and it is used at own risk.
# https://pw999.wordpress.com
# v0.1 - 2014-05-01
# * Initial release


#Step 1: call Github API and find everything with 1 or more stars and sort result on number of stars. Then grep the 10 first 'clone_urls' found and remove unneeded chars using following sed file:
#
#s/"//g
#s/,//g
#s/clone_url//g
#s/://

curl -s "https://api.github.com/search/repositories?q=stars:%3E1&sort=stars" | grep -i "clone_url" -m 10 | sed -f seds > urls.out

# Step 2: clone the top 10 projects on disk
xargs -a urls.out -n 1 git clone
# Too lazy :)
mkdir output

#  List all folders (github repo's), filter out the current directory '.' then forward it to the swearcount script and redirect the output
find . -maxdepth 1 -type d | grep -e '[a-zA-Z0-9/]' | sed s/\\.\\///g | xargs -I{} sh -c "./swearcount.sh ./{} > output/{}.out"

# Generate output file
# Get header and append projectname
cd output
sed -n '1p' output.out | sed s/^/"project "/ > result.txt

# Get numbers and append name
find . -type f -not -name output.out -not -name result.txt | xargs -n 1 -I{} sh -c "echo -n '{} ' && sed -n '2p' {}" >> result.txt

Disclaimer: results come as they are, I do not guarantee that they are 100% correct. This is just something I did for the fun, no pun intented.

Follow

Get every new post delivered to your Inbox.

Join 43 other followers