— React-Native Programmierer . Patrick Tresp

Archive
Allgemein

While working with reports for a service running on postgres, you want to make sure, that you can also run statistics on the data from that service. Most of the time, reports where made with same users, als the data was written ( experienced this in multiple companies ).

So lets take a step back and think of what reports are. It is analysis on data that is stored to create something humans can understand. Analysis does not change data, so we actually do not need any rights on that data – except reading.

To prevent a user that creates the analysis to change any data from the service, we will need to create a read-only user in postgres. This is pretty straight-forward, but also very often neglected

# log into postgres
sudo -upostgres psql postgres
 
 
# create user
CREATE ROLE readonly WITH LOGIN ENCRYPTED PASSWORD 'safe-password-here';
 
 
# connect to desired database
 
\connect 'database-name'
 
 
# grant select access and set default permissions
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;

With this, the user shall be able to SELECT any of the tables in this schema, but not able to UPDATE any.

Read More

When getting serious in creating apps with react-native, there’s more than just react and some coding.
At some point you will need to digg into XCode and it’s gui, which is a pain in the a$$ i believe.

Thanks to this article: https://medium.com/@kelleyannerose/react-native-ios-splash-screen-in-xcode-bd53b84430ec creating a xcode storyboard file is now an easy thing and the most important functions are explained well.

 

Thanx!

 

Read More

A Snippet which is very handy, is to determine, if something is above the fold AND also within the viewable area. Above the fold does not necessarily mean – visible.

var element = jQuery("#canvas");
var pageTopValue = element.offset().top + element[0].scrollHeight;
var viewable = jQuery(window).scrollTop()+ jQuery(window).height();
 
if( jQuery(window).scrollTop() > pageTopValue ){
 console.log( "Element hidden (above viewable area)" );
}
else if( viewable < element.offset().top ){
console.log( "Element hidden (below viewable area)" );
 
}
else{
console.log( "Element visible! (within viewable area)" );
}
Read More

 

for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done

Read More

Setting up a webserver is not one of the things i do daily, therefore a reminder:

Case-insensitivity in URLs might be explicit wanted on a specific domain on webserver.

Therefore create a .htaccess file containing those 2 lines

CheckSpelling On
CheckCaseOnly On

also slightly important is to change directorys rights and all containing date to „750“.

The Apache module mod_rewrite needs to be activated!

 

Read More

Just to have a short note, since it can save an evening or two.
If wanting to delete all files e.g. with .mp4 just use MacOSX Terminal and type

find . -name *.mp4 -type f -exec rm -r {} \;

make sure to be in correct directory and maybe you want to doublecheck the results first

find . -name *.mp4 -type f

Read More

Also this time, i want to write a very little summary of btplay in cologne, since i just got back from vacation, a lot is already out of mind.

Luca Sale
– keywords: phonegap, ripple, cloud9

Nico Zimmermann
– keywords: schau, passion project time ( save a month a year to just to passion projects )

Tim Ahrens
– keywords: fontfonter ( try fonts on any website )

Grant Skinner
– keywords: technitone, createjs

Thanks also to the great talks:

– Marcin Wichary
– Seb Lee
– Frank Reitberger
– Joshua Davis ( still cracking somethimes  and thank you for this: „the work you make is the type of work you’ll get hired to do“ )
– Sebastian Golash

Read More

Whithout writing too much about it for today, the best way ( i can always only speak for myself ) to call a function with setTimeout in JavaScript is:


var myTimeout = 400;
setTimeout(function(){ callFunction(parameter[s]) }, myTimeout);

function callFunction( parameter[s] )
{
// Do some Stuff here with the parameter[s]
}

Especially when a Parameter is a „multiple Word – String“ (e.g. „Hello Everyone, i am a multiple word String!“ ), using a „closure“ will be the way that works also in Internet Explorer 🙂

Read More

When working with JQuery, it seems all work is taken over by the library.
Actually it does, unless a client tells you afterwards, Internet Explorer 8 is still his/her weapon of choice, next to the ipad of course.
A really funny combination of technical aspects, but client is king, lets make him feel that way.

A real pain is that IE8 is not able to use event.preventDefault() nor event.stopPropagation().

For this, its helpful to use a function that will end the event, no matter what browser:

Step 01. make sure to stop Events

function stopEvent(e) {
 
	if(!e) var e = window.event;
 
	//e.cancelBubble is supported by IE -
        // this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;
 
	//e.stopPropagation works only in Firefox.
	if ( e.stopPropagation ) e.stopPropagation();
	if ( e.preventDefault ) e.preventDefault();		
 
       return false;
}

Step 02: adding and removing the listeners.

Since IE (8) does not support addEventListener or removeEventListener etc. the element needs to be checked, whether it supports addEventListener or attachEvent ( IE )

function addListeners( el )
{// Allow function call without passing parameters
	var e = el;
	if( !e )  e = document.getElementById('myDiv');
	var el = e;
 
	if( el )
	{
		if( el.addEventListener )
		{	
			el.addEventListener('mouseup', onMouseUp, true);
			el.addEventListener('mousemove', onMouseMove, true);
			el.addEventListener('touchstart', onTouchStart, true);
			el.addEventListener('touchmove', onTouchMove, true);
			el.addEventListener('touchend', onTouchEnd, true);			
		}else if( el.attachEvent ) {
                        // make sure mouse events have the prefix <strong>on</strong>
			el.attachEvent('onmouseup',    onMouseUp);		
			el.attachEvent('onmousemove',    onMouseMove);
			el.attachEvent('touchstart',   onTouchStart);
			el.attachEvent('touchmove',    onTouchMove);
			el.attachEvent('touchend', onTouchEnd);				
		}   
	}
}
// also remove the Listeners correctly:
 
function removeListeners( el )
{	var e = el;
	if( !e )  e = document.getElementById('myDiv');
	var el = e;
	if( el )
	{
		if( el.removeEventListener )
		{	
			el.removeEventListener('mouseup', onMouseUp);
			el.removeEventListener('mousemove', onMouseMove);
			el.removeEventListener('touchstart', onTouchStart);
			el.removeEventListener('touchmove', onTouchMove);
			el.removeEventListener('touchend', onTouchEnd);
		}else if( el.detachEvent ) {
			el.detachEvent('onmouseup',    onMouseUp);
			el.detachEvent('onmousemove',    onMouseMove);
			el.detachEvent('touchstart',   onTouchStart);
			el.detachEvent('touchmove',    onTouchMove);
			el.detachEvent('touchend', onTouchEnd);				
		}  
	}
}

Now its just a Matter of Needs, what to do within the handlers:
an Example could be

 function onMouseUp(e) {
	log('-&gt; mouse up');
	e.touches = [{clientX: e.clientX, clientY: e.clientY}];
	removeListeners();
	stopEvent(e);
}
 
function onMouseDown(e) {
	log('-&gt; mouse down');
	addListeners();
	e.touches = [{clientX: e.clientX, clientY: e.clientY}];
	onTouchStart(e);
	stopEvent(e);
}
 
function onMouseMove(e) {
	log('-&gt; mouse move');
	e.touches = [{clientX: e.clientX, clientY: e.clientY}];
	onTouchMove(e);
	stopEvent(e);
}
 
function onTouchStart(e) {
	log('-&gt; touch start');
	//do something with e.touches[0].clientX or e.touches[0].clientY
   stopEvent(e);
}
 
function onTouchMove(e) {
	log('-&gt; touch move');
	//do something with e.touches[0].clientX or e.touches[0].clientY
	stopEvent(e);
}
 
function onTouchEnd(e) {
	log('-&gt; touch end');
	if( !is_touch_device() ) removeListeners();
}

And to not get any errors, add function log and function is_touch_device…

function log(str) {
	var c;
	c = document.getElementById('console');
	c.innerHTML = str + '
' + c.innerHTML;
}
 
function is_touch_device() {
  return !!('ontouchstart' in window) ? 1 : 0;
}

Finally, if it is an Touch device, you want to add the listeners onLoad of the document, on regular devices on MouseDown. Call this function on documen_ready or onLoad.

function init() {
 
	var el;
    el = document.getElementById('myDiv');
 
	if( el.addEventListener )
	{
		el.addEventListener('mousedown', onMouseDown, false);
	}else if( el.attachEvent ) {
		el.attachEvent('onmousedown',    onMouseDown);
	}
	if( is_touch_device() ) addListeners();
 
 
}

it works so far in IE8/9, FireFox 3.6.1+, Safari and mobile Safari ( ios )

Read More

During a Projekt, i was wondering, why local use of HTML5 Videos was running, but online it failed.

It turned out, that the MIME-Types for .ogg or .webm were not correctly set. The Server served them as plain text-files.

To get the Server to add correct headers to the files, it is helpful to add those lines in your .htacess .

Not all of them are always neccessary.

AddType video/ogg .ogm 
AddType video/ogg .ogv 
AddType video/ogg .ogg 
AddType video/webm .webm 
AddType audio/webm .weba
AddType video/mp4 .mp4 
AddType video/x-m4v .m4v

Sometimes it’s that easy

Read More