Jump to content

felix

Members
  • Posts

    214
  • Joined

  • Last visited

  • Days Won

    8

Posts posted by felix

  1. Hi Horst,

    would it be possible to implement a feature that overwrites the configuration variables (server, password...) from a config or .env File?
    We've got several sites that do auto-deployments to different servers based on the git branch that is used. Currently, when deploying the local development version to a staging system we're copying the dev database and need to adjust the settings by "hand" (we've written a script for that). Having a file based configuration would make it possible to just dump a file on the server and save the config variables in it.

    • Like 1
  2. On a sidenote jwt is perfect when things need to "scale" (i.e. in a microservice architecture). Just share the secret across multiple instances and you don't have to care about syncing sessions and related data. The backend thus can be "stateless" (regarding logins) and just used to deliver data.

     

    • Like 3
  3. I'll also start tracking my vital signs, soon. But after a lot of "research" I'm going to to buy a Garmin Vivosmart HR (longer lifetime, more accuracy...) instead. I'm also slightly overweight atm but cycle about 100-150km(63~93miles) per week (for the last 5 months). Currently I use Strava to track my rides. As I'm always cycling with my mobile phone as a tracker there was no need for a gps enabled device (otherwise I would most likely have chosen the vivioactive hr). You should really check out garmin products instead of fitbit from what I've heard and read.

    • Like 1
  4. Hey folks,

    I'm trying to cache a lot of event & news entrys that get loaded on several pages. There are two conditions that - when met - require the cache to be invalidated:

    - A page with the Template "news-detail" is saved

    - The Cachefile is older than "Today at midnight"

    The first condition is easy (see code below). What about the second?

    Is there a way to combine both conditions (template change and caching time) using the cache api? Will I have to use cron/lazycron to purge the cache every 24hrs?

    	private function getCachedNews($parentId, \PageArray $filter = null) {
    
    		$template = wire('templates')->get(self::NEWS_TEMPLATE);
    		$cache = wire('cache');
    		$addedFilters = '';
    		if(!is_null($filter)) $addedFilters = '_' . $filter->implode('', 'name');
    
    		$newsSelector = 'news_' . $parentId . $addedFilters;
    
    		$news = $cache->get($newsSelector, $template, function($pages) {
    			// here be newslogic dragons [...]
    			return $retVal;
    		}); 	
    
    		return $news;
    
    	}
    
  5. Google today announced it's competitor to Facebooks "Instant Articles": "AMP"(Accelerared Mobile Pages)HTML. Based on open source technologies (Basically it's a set of Web Components and a JS-Framework that loads and caches resources) it seems very promising. As far as I understand media is cached, served and proxied by google (and some tech partners). 

    Btw: processwire as a system could benefit from/partner with it, too: https://www.ampproject.org/faq/#accelerated-mobile-pages-9

    I'm really looking forward to playing around with it. Anyone else already fired up his editor and started fiddling around?

    • Like 4
  6. I would love to have a possibility to embed videos via CKEDITOR the same way images are embedded (instead of shortcodes). This would be so much easier (i mean: after all video is just another html tag). Any plans on doing this?

    If you ain't got time / plans to do this I'd be happy to help you with it (I thought about building this as a module for quite a long time).

    • Like 1
  7. Maybe this helps you. I'm using it in one of our sites for the exact same thing (you'll have to adjust the table names and get the coordinates of the given zip, though). The SQL Query uses the Haversine formula ( http://www.plumislandmedia.net/mysql/haversine-mysql-nearest-loc/ ) to find coordinates within the given radius.

    	    /**
    	     * Retrieves a list of address records residing within the given $radius of the given geo location
    	     *
    	     * @param float $lat
    	     * @param float $lng
    	     * @param int $radius
    	     * @return array
    	     */
    
    		private function proximitySearch($lat, $lng, $radius = 20) {
    
    	        $sql = <<<SQL
    
    SELECT * FROM (
    	SELECT *,
    		(
    			( 2 * 6378.2 ) *
    			ATAN2(
    				( SQRT(
    					 POW( SIN( ( ( $lat * PI() / 180 ) - ( lat * PI() / 180 ) ) / 2 ), 2 ) +
    					 COS( lat * PI() / 180 ) *
    					 COS( $lat * PI() / 180 ) *
    					 POW( SIN( ( ( $lng - lng ) * PI() / 180 ) / 2 ), 2 )
    				       )
    				),
    				( SQRT(
    					1 - (
    					 POW( SIN( ( ( $lat * PI() / 180 ) - ( lat * PI() / 180 ) ) / 2 ), 2 ) +
    					 COS( lat * PI() / 180 ) *
    					 COS( $lat * PI() / 180 ) *
    					 POW( SIN( ( ( $lng - lng ) * PI() / 180 ) / 2 ), 2 )
    					)
    				       )
    				)
    		    )
    		)
    		AS distance
    	FROM field_address_team
    	ORDER BY distance
    ) AS distributordistance
    WHERE distance <= $radius;
    
    SQL;
    
    			$result = wire('db')->query($sql);
    			if(!function_exists('mysqli_fetch_all')) {
    				$retVal = [];
    				while ($row = $result->fetch_assoc()) {
    						$retVal[] = $row;
    				}
    			} else {
    				$retVal = $result->fetch_all(MYSQLI_ASSOC);
    			}
    			return $retVal;
    
    		}
    

    Usage (in this specific example the radius is extended by the factor 3 until at least 3 locations are found or the radius has been extended 3 times which would be 540km [(((20*3)*3)*3)] with default radius settings ):

    		public function getTeamsInRadius() {
    
    			$teamsArr = new \PageArray();
    			$searchCount = 0;
    
    			while (count($teamsArr) < 3 && $searchCount <= 3 ) {
    
    			    try {
    			        // extend search radius by factor 3 as long as result set counts less than 3 hits
    			        //
    			      	$teams = $this->proximitySearch($this->latitude, $this->longitude, $this->radius * pow(3, $searchCount));
    
    			      	foreach( $teams as $team ) {
    
    			      		$teamsArr->append( wire('pages')->get($team['pages_id']) );
    			      	}
    
    			        $searchCount++;
    
    			    } catch (\Exception $e) {
    			        break;
    			    }
    
    			}
    			return $teamsArr;
    
    		}
    

    A good idea when using this is to cache the results (see this blog entry for examples) for each entered ZIP until new entries are added to the database as the SQL Queries are pretty performance intensive. The benefit of this method is: You don't have to query Google Maps (or another GeoService) every time you're searching for locations.

    • Like 7
  8. As I've already commented under the article: It seems like there was an internal job called "write something about processwire" and somebody decided to give it a go because there was nothing else to do and he was bored or something. All his other (wordpress) articles are packed up with images, code examples and so on. It's a shame :/

    • Like 4
  9. I'm using Windows at the office and my macbook at home for work. Both worlds have their pros, cons and tools I'm missing on "the other system". I'm also using conemu for quite a while and found it to be the best console for Windows (in combination with cygwin). On Mac there is a similar tool: totalconsole. I configured both to scroll down from the top of the screen on shift+^ (quake players might remember that keys and style :)). My primary editor on both machines is sublime text 3 with the same setup. This makes switching systems every few hours a real no-brainer (apart from some system dependant shortcut/keybinding stuff).

    • Like 1
×
×
  • Create New...