Skip to content

Instantly share code, notes, and snippets.

View Nyholm's full-sized avatar

Tobias Nyholm Nyholm

View GitHub Profile
@Nyholm
Nyholm / gist:317df136ded2087649d0c9c464285cb1
Last active August 15, 2023 21:16
Show who contributed to your vendors folder
# Install git fame
gem install git_fame
# Install all vendors with source
rm -rf vendor/*
composer update --prefer-source
# Do the calculations. This might take 30 minutes to complete.
rm output.txt
find ./vendor -type d -depth 2 ! -path "./vendor/composer" -exec echo {} \; -exec git fame --sort=loc --hide-progressbar --repository={} \; >> output.txt
@Nyholm
Nyholm / Runner.php
Last active September 7, 2021 18:28
A simple middleware runner for PSR7
<?php
declare(strict_types=1);
namespace App;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Runner
@Nyholm
Nyholm / instagram.php
Last active October 26, 2019 17:19
Get instagram images 2018-10-16
function getInstagramImages($username, $limit = 5) {
$url = 'https://www.instagram.com/'.$username;
$response = file_get_contents($url);
if (!preg_match('|<script type="text\/javascript">window\._sharedData = (.*?);<\/script>|sim', $response, $matches)) {
return [];
}
$json = json_decode($matches[1], true);
$edges = $json['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'];
$images = [];
for($i = 0; $i<$limit; $i++) {
@Nyholm
Nyholm / gist:4c2a960531d5d81c062b
Last active November 30, 2017 19:58
Display flash messages in Symfony2
{# Check if we got a session without creating one #}
{% if app.request.hasPreviousSession %}
{# Check if we got some flash messages #}
{% if app.session.flashbag.peekAll()|length > 0 %}
<div id="flash">
{# Loop all types of flash messages #}
{% for type, flashMessages in app.session.flashbag.all() %}
{# For all flash messages with this type #}
{% for idx, flashMessage in flashMessages %}
<div class="flash-item flash-type-{{ type }}">
@Nyholm
Nyholm / gist:25abd12b23ca6e8324a9b920687a4fa2
Created May 23, 2017 12:59
See if I have code in your app
echo "Remove vendor folder"
rm -rf ./vendor/*
echo "Get all vendors again but with the .git folder
composer install --prefer-source
echo "Find a list of all repositories Tobias Nyholm has contributed to
find . -name .git -type d -prune -exec bash -c "cd '{}' && git shortlog -snc | grep 'Tobias Nyholm' > /dev/null && echo '{}' " \;
@Nyholm
Nyholm / gist:1003e418eade21b0cecb1e75c9fab648
Created January 18, 2017 08:11
Contributors to Symfony ordered by contributions of current master. If you created a feature that has been removed it will not show up here.
Statistics based on master 2017-01-18 08:00:00 UTC
Active files: 5,534
Active lines: 662,427
Total commits: 27,200
Note: Files matching MIME type image, binary has been ignored
Created by https://github.com/oleander/git-fame-rb
+----------------------------------------------------+---------+---------+-------+--------------------+
@Nyholm
Nyholm / function.php
Created April 17, 2016 19:13
Example of logging plugin to Wordpress
add_action('aal_insert_log', 'storeActivityToFile');
function storeActivityToFile($args) {
// Example
$args = array(
'action' => 'activated',
'object_type' => 'Plugin',
'object_subtype' => '',
'object_name' => 'Activity Log',
'object_id' => 0,
@Nyholm
Nyholm / AppKernel.php
Created August 12, 2016 11:27
A microservice example of a AppKernel
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Psr\Http\Message\RequestInterface;
use Happyr\Geocoder\Middleware\Middleware;
use Relay\RelayBuilder;
use Zend\Diactoros\Response;
@Nyholm
Nyholm / convert.php
Last active September 4, 2015 09:44
Convert csv files to json files to import to Loco
<?php
require 'vendor/autoload.php';
$dir = '/Users/tobias/path';
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->in($dir)->depth('== 0')->name('*.csv');
/** @var \Symfony\Component\Finder\SplFileInfo $file */