Skip to content

Instantly share code, notes, and snippets.

@mpociot
mpociot / CanBeReplicated.php
Created June 12, 2019 12:32
Add the ability to replicate Laravel models to other models.
<?php
use Illuminate\Support\Arr;
trait CanBeReplicated
{
public function replicateTo(string $model, array $with = null, array $except = null)
{
$defaults = [
$this->getKeyName(),
@mraaroncruz
mraaroncruz / steps.md
Last active April 16, 2024 07:22
Get the Telegram channel ID

To get the channel id

  1. Create your bot with botfather
  2. Make you bot an admin of your channel

Simplest way (via @anhtuank7c)

Go to Telegram web and open a channel, get the ID from -[channel id] from hash in the path

https://web.telegram.org/k/#-9999999999999

@budidino
budidino / string-truncate.swift
Last active April 3, 2024 20:11 — forked from vicc/string-truncate.swift
String truncate extension for Swift 4
extension String {
/*
Truncates the string to the specified length number of characters and appends an optional trailing string if longer.
- Parameter length: Desired maximum lengths of a string
- Parameter trailing: A 'String' that will be appended after the truncation.
- Returns: 'String' object.
*/
func trunc(length: Int, trailing: String = "…") -> String {
return (self.count > length) ? self.prefix(length) + trailing : self
@leymannx
leymannx / webhook.php
Last active November 6, 2018 14:43 — forked from cowboy/github_post_recieve.php
PHP webhook to pull and Gulp build automatically after push
<?php
if ( isset($_POST['payload']) && $_POST['payload'] ) {
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser git pull');
echo shell_exec('cd /var/www/mydrupal/sites/all/themes/mytheme/ && sudo -u myuser node ./node_modules/gulp/bin/gulp.js mygulptask');
// Adding the drush will cause the delivery being displayed as unsuccessful. Means GitHub doesn't wait so long. The command will run nevertheless.
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser drush @sites cc all -y');
}
// Should return www-data
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active May 1, 2024 19:56
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@PierceZ
PierceZ / Observable.java
Created May 14, 2017 13:30
Simple RxJava observable example to make a network request.
Observable.fromCallable(() -> {
Request request = new Request.Builder()
.url(url)
.build();
try {
Response response = sHttpClient.newCall(request).execute();
return response.isSuccessful();
} catch (IOException e) {
Log.e("Network request", "Failure", e);
}
@paulredmond
paulredmond / ValidateMailgunWebhook.php
Created April 24, 2017 21:55
Laravel Middleware to Validate a signed Mailgun webhook
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
/**
* Validate Mailgun Webhooks
* @see https://documentation.mailgun.com/user_manual.html#securing-webhooks
@milesw
milesw / StaticCorsValetDriver.php
Created December 3, 2016 08:02
Laravel Valet driver that serves static files with CORS header
<?php
class StaticCorsValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
@harryfinn
harryfinn / letsencrypt-wordpress-setup.md
Last active November 12, 2023 10:21
Instructions on how to setup a Letsencrypt SSL certificate on a WordPress site

Letsencrypt (for WordPress sites)

Note: This setup assumes you are running Ubuntu 16.04 OS with Apache 2.4.23, older versions of Ubuntu (i.e. 14.04) require minor configuration changes in order for this setup to work.

Setup

Follow the install instructions for certbot (letsencrypt's SSL manager) on https://certbot.eff.org/, making sure to select the correct server OS version.

Note: You only need to complete the Install section, then return to this README in order to setup your SSL

@maciekish
maciekish / resetXcode.sh
Created August 10, 2016 10:13
Reset Xcode. Clean, clear module cache, Derived Data and Xcode Caches. You can thank me later.
#!/bin/bash
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
open /Applications/Xcode.app