Skip to content

Instantly share code, notes, and snippets.

View nesk's full-sized avatar

Johann Pardanaud nesk

View GitHub Profile
@nesk
nesk / README.md
Last active October 26, 2022 09:29
Delete the latest workflow runs of a repo (up to 100)

A fish oneliner to delete the latest workflow runs of a repo.

Install the GitHub CLI and replace <owner>/<repository> with your repository.

You can also change ?per_page=100 with the number of runs you want to delete.

@nesk
nesk / xdebug-toggle.php
Last active April 24, 2020 09:47
Xdebug Toggler: A simple command line tool to enable/disable Xdebug in your PHP config (only if installed via Homebrew on macOS).
#!/usr/bin/env php
<?php
/**
* Requirements: PHP installed via Homebrew on macOS.
*
* Installation: Copy the content of this file in `~/xdebug`.
*
* Usage:
*
@nesk
nesk / ThrowerChecker.php
Created October 8, 2019 11:46
How to mock an exception
<?php
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Firewall\AccessListener;
class ThrowerChecker
{
public function isThrownByFirewall(AccessDeniedException $exception): bool
{
// Walking through the stack frames and returning true if one of them is triggered by a specific class
@nesk
nesk / helpers.php
Last active July 8, 2019 15:25
A helper to open the content of a Symfony/Laravel response in your browser, really useful for test debugging.
<?php
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
/**
* Opens a response in the default browser.
*/
function open_response(Response $response): void
@nesk
nesk / .gitignore
Last active June 20, 2019 13:23
PHPUnit - Data providers memory showcase
/vendor
composer.lock
@nesk
nesk / DefaultController.php
Created November 29, 2018 15:15
Report an exception with Symfony without throwing
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
@nesk
nesk / MainActivity.kt
Last active June 26, 2018 14:35
Android pre-populated database (full)
package com.example.example
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@nesk
nesk / MyDatabaseHelper.kt
Last active June 26, 2018 14:34
Android pre-populated database (installing on read)
package com.example.example
// ...
class ActsDbHelper(val context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
// private val preferences: SharedPreferences = ...
private fun installedDatabaseIsOutdated(): Boolean {
// ...
@nesk
nesk / MyDatabaseHelper.kt
Created June 26, 2018 10:28
Android pre-populated database (update methods)
package com.example.example
// ...
import android.content.SharedPreferences
class ActsDbHelper(val context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
private val preferences: SharedPreferences = context.getSharedPreferences(
"${context.packageName}.database_versions",
Context.MODE_PRIVATE
@nesk
nesk / MyDatabaseHelper.kt
Last active June 26, 2018 14:18
Android pre-populated database (installation method)
package com.example.example
// ...
import java.io.File
import java.io.FileOutputStream
class ActsDbHelper(val context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
private fun installDatabaseFromAssets() {
val inputStream = context.assets.open("$ASSETS_PATH/$DATABASE_NAME.sqlite3")