Skip to content

Instantly share code, notes, and snippets.

Tobias Nyholm Nyholm

Block or report user

Report or block Nyholm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Nyholm
Nyholm / Runner.php
Last active Oct 26, 2019
A simple middleware runner for PSR7
View Runner.php
<?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 Oct 26, 2019
Get instagram images 2018-10-16
View instagram.php
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:317df136ded2087649d0c9c464285cb1
Last active Apr 2, 2018
Show who contributed to your vendors folder
View gist:317df136ded2087649d0c9c464285cb1
# 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 / gist:25abd12b23ca6e8324a9b920687a4fa2
Created May 23, 2017
See if I have code in your app
View gist:25abd12b23ca6e8324a9b920687a4fa2
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 Jan 18, 2017
Contributors to Symfony ordered by contributions of current master. If you created a feature that has been removed it will not show up here.
View gist:1003e418eade21b0cecb1e75c9fab648
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 / AppKernel.php
Created Aug 12, 2016
A microservice example of a AppKernel
View AppKernel.php
<?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 / function.php
Created Apr 17, 2016
Example of logging plugin to Wordpress
View function.php
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 / convert.php
Last active Sep 4, 2015
Convert csv files to json files to import to Loco
View convert.php
<?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 */
@Nyholm
Nyholm / gist:4c2a960531d5d81c062b
Last active Nov 30, 2017
Display flash messages in Symfony2
View gist:4c2a960531d5d81c062b
{# 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 }}">
You can’t perform that action at this time.