├── .editorconfig ├── LICENSE.md ├── README.md └── snippets ├── js └── google-maps-world-view.js └── php ├── simple-log.php └── string-to-type.php /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Spatie bvba 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [](https://supportukrainenow.org) 3 | 4 | # Snippets 5 | 6 | We aspire to put as much of our code as realistically possible in packages. However, in some cases code can be either to specific to a project, or simply isn't package-worthy for other reasons. The goal of this repository is to have a centralized location for smaller code snippets and recipes that fall in to that category. 7 | 8 | ## Support us 9 | 10 | [](https://spatie.be/github-ad-click/snippets) 11 | 12 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). 13 | 14 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). 15 | 16 | ## About Spatie 17 | Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource). 18 | 19 | ## License 20 | 21 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 22 | -------------------------------------------------------------------------------- /snippets/js/google-maps-world-view.js: -------------------------------------------------------------------------------- 1 | { 2 | // By setting the zoom level to 0, the map will try to fit the entire world in your viewport 3 | const zoom = 0; 4 | 5 | // You might need to tweak these depending on your map's aspect ratio 6 | const center = { lat: 45, lng: 12 }; 7 | 8 | // Set up the bounds you want to use as a constraint while dragging the map 9 | // These values represent all continents minus antarctica 10 | const fitBounds = new google.maps.LatLngBounds( 11 | new google.maps.LatLng(-50, -179), 12 | new google.maps.LatLng(84, 179) 13 | ); 14 | 15 | const map = new google.maps.Map({ zoom, center, fitBounds /* ,... */ }); 16 | 17 | let lastValidCenter = map.getCenter(); 18 | 19 | google.maps.event.addListener(map, 'center_changed', () => { 20 | if ( 21 | map.getZoom() >= 2 && 22 | fitBounds.contains(map.getBounds().getNorthEast()) && 23 | fitBounds.contains(map.getBounds().getSouthWest()) 24 | ) { 25 | lastValidCenter = map.getCenter(); 26 | return; 27 | } 28 | 29 | map.panTo(lastValidCenter); 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /snippets/php/simple-log.php: -------------------------------------------------------------------------------- 1 |