Skip to content

Instantly share code, notes, and snippets.

@graste
graste / travisci.yml
Created June 30, 2015 21:14
PHP Composer TravisCI
language: php
php:
- 5.6
- 7
matrix:
include:
- php: 5.6
env: dependencies=lowest
@graste
graste / git-move-multiple-files.md
Last active August 29, 2015 14:24
Git mv multiple files and delete branch locally or remote
  • find local files and git mv them: find . -name '*foo*' -exec sh -c 'file={}; git mv $file ${file/foo/bar}' \;
  • remove a local branch: git branch -d <branchName>
  • remove a remote branch from the server: git push origin :<branchName>
  • as of git v1.7.0: git push origin --delete
@graste
graste / base36.php
Last active August 29, 2015 14:24
"Base 36 is the most compact case-insensitive alphanumeric numeral system using ASCII characters."
<?php
// https://www.darklaunch.com/2009/07/31/base36-encode-and-decode-using-php-with-example-base36-encode-base36-decode
function base36_encode($base10) {
return base_convert($base10, 10, 36);
}
function base36_decode($base36) {
return base_convert($base36, 36, 10);
@graste
graste / curl-basic-auth.md
Last active April 11, 2016 08:07
curl authentication

Accept insecure https and use basic auth:

curl -k --user name:password https://www.example.com
curl --user name:password https://www.example.com
@graste
graste / map-deep-get.scss
Created July 14, 2015 21:05
map deep get in scss
@function map-fetch($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
@if type-of($map) == 'null' {
@return $map;
}
}
@return $map;
@graste
graste / elasticsearch.md
Created July 15, 2015 08:37
elasticsearch

curl -X :///

@graste
graste / address-ref.php
Last active December 1, 2021 15:54
JSON-Schema with simple $ref resolution (reference to local definition)
<?php
ini_set('display_errors', 1);
require __DIR__ . '/vendor/autoload.php';
$json = '{
"shipping_address": {
"street_address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC"
},
@graste
graste / oneof-address-ref.php
Created September 3, 2015 09:56
JSON-Schema oneOf with $ref definitions failing
<?php
ini_set('display_errors', 1);
require __DIR__ . '/vendor/autoload.php';
$json = '{
"address": {
"street_address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC",
"use_for_billing": true
@graste
graste / gist:c06e95e3932e60289ad5
Created October 16, 2015 09:23 — forked from oleksii-zavrazhnyi/gist:968e5ea87e99d9c41782
BASH Absolute path of current script
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@graste
graste / responsive-image.md
Last active April 3, 2016 11:31
RESPONSIVE <IMG> WITH SRCSET + SIZES
<img src="fallback-placeholder-image.jpg"

     srcset="largest-image.jpg  960w,
             larger-image.jpg   640w,
             medium-image.jpg   480w,
             smallest-image.jpg 320w"

     sizes="(min-width: 1280px) 480px,
 (min-width: 1024px) 444px,