Skip to content

Instantly share code, notes, and snippets.

View danjdewhurst's full-sized avatar

Dan danjdewhurst

  • http://reckless.agency/
  • England, United Kingdom
View GitHub Profile
@danjdewhurst
danjdewhurst / cf-ips.sh
Created June 19, 2024 16:22
Bash script to update a htaccess file with rules to block non-CloudFlare requests via IP
#!/bin/bash
# URL to fetch Cloudflare IP ranges
ipv4_url="https://www.cloudflare.com/ips-v4"
ipv6_url="https://www.cloudflare.com/ips-v6"
# Temporary files to store IP ranges
tmp_ipv4="/tmp/cloudflare_ipv4.tmp"
tmp_ipv6="/tmp/cloudflare_ipv6.tmp"
@Braunson
Braunson / AppServiceProvider.php
Created January 6, 2022 21:27
Detect if a request is from Livewire or not, useful when you have middleware that needs to ignore Livewire requests. Drop this in the boot method.
<?php
// Detect requests from Livewire
Request::macro('isFromLivewire', function() {
return $this->headers->has('x-livewire');
});
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
@mutin-sa
mutin-sa / Top_Public_Time_Servers.md
Last active July 17, 2024 01:35
List of Top Public Time Servers

Google Public NTP [AS15169]:

time.google.com

time1.google.com

time2.google.com

time3.google.com

@leahtard
leahtard / node.twig.html
Last active June 9, 2022 18:32
Get file url in node for Drupal 8 twig template
{# Get URL of single file field #}
{{ node.field_file.entity.uri.value }}
{# Get URL of multi file field #}
{{ node.field_file['#items'].entity.uri.value }}
{# Trun into link #}
{{ file_url(node.field_file.entity.uri.value) }}
{# Check if there is at least one value #}
@jonhattan
jonhattan / example_ajax.php
Last active November 17, 2023 15:28
Drupal 8 - detect if we're in an ajax request, and if building the form for the first time, or re-building within the input processing.
<?php
use Drupal\Core\Form\FormStateInterface;
function example_ajax_form_alter() {
$ajax_form_request = \Drupal::request()->query->has(FormBuilderInterface::AJAX_FORM_REQUEST);
if ($ajax_form_request) {
if (!$form_state->isProcessingInput()) {
\Drupal::logger('example')->notice('first pass');
}
@niksumeiko
niksumeiko / git.migrate
Last active July 19, 2024 21:32
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@kpeatt
kpeatt / gist:5154680
Last active November 7, 2019 23:29 — forked from tvandervossen/gist:1231476
Viewport sizes for iPad, iPhone 4 and under, and iPhone 5 and up.
iPad (Actual pixels in brackets)
1024 × 690 (2048 x 1380) In landscape on iOS 4.3
1024 × 672 (2048 x 1344) In landscape on iOS 5
768 × 946 (1536 x 1892) In portrait on iOS 4.3
768 × 928 (1536 x 1856) In portrait on iOS 5
1024 × 660 (2048 x 1320) Always showing bookmarks bar in landscape on iOS 4.3
1024 × 644 (2048 x 1288) Always showing bookmarks bar in landscape on iOS 5
768 × 916 (1536 x 1832) Always showing bookmarks bar in portrait on iOS 4.3
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}