Skip to content

Instantly share code, notes, and snippets.

View rexxars's full-sized avatar

Espen Hovlandsdal rexxars

View GitHub Profile
@rexxars
rexxars / example.php
Created June 27, 2017 11:37
Image renderer, PHP-client
<?php
require_once './vendor/autoload.php';
$client = new Sanity\Client([
'projectId' => '3do82whm',
'dataset' => 'production',
]);
$doc = $client->getDocument('47abbe60-f184-4eff-99e0-3a85c5c07c3a');
$html = Sanity\BlockContent::toHtml($doc['body'], [
@rexxars
rexxars / jsondump.jsx
Last active December 19, 2019 05:22
React JSON dump component
import React from 'react';
class JsonDump extends React.Component {
static propTypes = {
children: React.PropTypes.any
}
render() {
return <pre>{JSON.stringify(this.props.children, null, 4)}</pre>
}
2 bokser kokosmelk
4 dl vann
7-8 teskjer green curry paste
1 sjalottløk
1 rødløk
3 fedd hvitløk
"En god dæsj" fiskesaus (1 ss? 2 ss?)
4 chili
1 gulerot
<?php
$postData = array(); // Fill this with your JSON/JS
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json'. "\r\n",
'content' => json_encode($postData)
)
));
<?php
new AuthArrayAdapter([
// Shorthand/old style access (read+write for all endpoints)
'oldPubKey' => 'oldPrivKey',
'pubKey1' => [
'someRoPrivateKey' => ['images.get', 'image.get', 'metadata.get'],
'someRwPrivateKey' => ['images.post', 'image.put', 'metadata.post']
],
@rexxars
rexxars / gist:8ce51e1b2dec75275919
Created August 15, 2014 13:42
SortBy with deep object access
'use strict';
function deep(obj, prop) {
var segs = prop.split('.');
while (segs.length) {
obj = obj[segs.shift()];
}
return obj;
}
// In some app (say, a flickr-image-app):
appApi.emit('image-selected-for-upload', { url: someUrl, source: 'flickr' })
appApi.on('image-uploaded', function(e) {
if (e.data.source !== 'flickr') {
return;
}
alert('Image uploaded');
});
@rexxars
rexxars / gist:9111474
Last active October 7, 2021 04:12
Async.js + imboclient.js
var imbo = new Imbo.Client('host', 'pub', 'priv');
var fileInput = document.querySelector('input[type=file]');
fileInput.addEventListener('change', uploadFiles, false);
function uploadFiles() {
async.mapSeries(
fileInput.files,
imbo.addImage.bind(imbo),
onFilesUploaded
@rexxars
rexxars / gist:5966465
Last active December 19, 2015 13:59
PHP array code standard
<?php
// Now:
$externalRelatedArticles = $relatedArticlesService->prepare(array('scope' => 'external',
'articleId' => $article->getId(),
'tagId' => $tagId,
'limitByDomain' => 2
));
// Suggested:
$externalRelatedArticles = $relatedArticlesService->prepare(array(
@rexxars
rexxars / gist:3748547
Created September 19, 2012 08:58
Imbo try/catch with imageExists
<?php
$fileName = 'someImage.png';
try {
if ($imbo->imageExists($fileName)) {
$photoHash = $imbo->getImageIdentifier($fileName);
} else {
$response = $imbo->addImage($fileName);
$photoHash = $response->getImageIdentifier();
}