Pagination is the process of dividing a long list of results into easier to consume pages. By only loading one page at a time, memory is preserved. This applies to RDBMS result sets, collections of serialized items in an API, or listings in list views of simple CRUD applications. Although the needs are often the same, many libraries define their own objects, or even use plain arrays to represent a paginated result. As a result, projects consuming these libraries often end up defining many adapters for those many libraries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
rm outdated-status.txt | |
touch outdated-status.txt | |
for package in `composer outdated | awk '{ print $1":"$4 }'`; | |
do | |
echo "New version: $package" > outdated-status.txt | |
composer why-not $package > outdated-status.txt | |
echo "----------" > outdated-status.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
if [ $# -ne 2 ]; then | |
echo "Usage: `basename $0` <pull> <branch>"; | |
exit 1; | |
fi | |
PULL="$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = <<<'GRAPHQL' | |
query GetUser($user: String!) { | |
user (login: $user) { | |
name | |
repositoriesContributedTo { | |
totalCount | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
workers=4 | |
STEP=$(psql -U svetluska -c "SELECT ceil(COUNT(*) / $workers) FROM svetluska.domination" -qtA svetluska) | |
time for ((i=0; i<$workers; i++)) | |
do | |
echo "UPDATE svetluska.domination SET geometry = t.geometry_wkt FROM (SELECT id, geometry_wkt FROM svetluska.domination ORDER BY id LIMIT $STEP OFFSET $STEP*$i) t WHERE domination.id = t.id"; | |
done | xargs -P $workers -I % psql -U svetluska -c "%" svetluska | |
#done | xargs -P 3 -I % echo % |
You can have a linear workflow with the array functions.
The following is unreadable:
$output = array_reduce(
array_map(
function($n) { return $n ** 2; }
array_filter($input, function($n) { return $n % 2 == 0; })
),
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'bundler/setup' | |
# TWO WAYS TO RUN THIS SCRIPT: | |
# ---------------------------- | |
# --->>> THE FIRST WAY> Run this script as executable: `./clone_gitlab_projects.rb` | |
# You need to make the script executable: `chmod +x gitlab_clone_all_repos.rb` | |
# ---- ANYTHING ABOVE THIS LINE IS ONLY REQUIRED IF YOU WANT TO RUN THE SCRIPT WITH SINGLE COMMAND `./clone_gitlab_projects.rb` ---- # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- psql -U postgres -h localhost -f /path/to/tardis.sql | |
SET statement_timeout = 0; | |
SET lock_timeout = 0; | |
SET client_encoding = 'UTF8'; | |
SET standard_conforming_strings = on; | |
SET check_function_bodies = false; | |
SET client_min_messages = warning; | |
SET row_security = off; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\PropertyAccess\PropertyAccessor; | |
use Symfony\Component\PropertyAccess\PropertyPath; | |
/** | |
* A property accessor that allows you to rewrite a property path for setters and getters. | |
*/ | |
class CustomPropertyAccessor extends PropertyAccessor | |
{ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "repository (owner/repository): " REPO | |
read -p "user: " USER | |
read -p "password: " -s PASS | |
# Delete default labels | |
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO/labels/bug" | |
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO/labels/duplicate" | |
curl --user "$USER:$PASS" --include --request DELETE "https://api.github.com/repos/$REPO/labels/enhancement" |