Skip to content

Instantly share code, notes, and snippets.

View bramus's full-sized avatar

Bramus bramus

View GitHub Profile
const changeValueInObject = (object, key, value) => {
if (key.indexOf('.') !== -1) {
const keyParts = key.split('.');
const firstPartOfKey = keyParts.shift();
return {
...object,
[firstPartOfKey]: {
...(object[firstPartOfKey] ?? {}),
...changeValueInObject((object[firstPartOfKey] ?? {}), keyParts.join('.'), value),
},
@bramus
bramus / feedback.md
Created March 13, 2019 22:02
RE: Designing An Aspect Ratio Unit For CSS

The addition of an aspect-ratio property would indeed solve this specific issue. Glad to see it's being discussed (once wrote an extensive post on this myself).

Thinking further on this, this solution is somewhat limited: it only solves the aspect ratio problem.

A more broader solution could be the introduction of a val() function. It would work like the var() function – which reads the value of a custom property – but then for reading values from other properties. The function would yield the computed value of the given property. Combine it with calc() and you're good to go.

In code, it would result in something like this:

.box {
<?php
// @ref https://twitter.com/brendt_gd/status/1065534180266782721
$a = range(5, 8);
$b = range(13,16);
$c = range(1,3);
$current = range(1,16);
@bramus
bramus / isSunSup.php
Last active November 6, 2024 14:29
PHP: Is The Sun Up (standalone version)?
<?php
function sunIsUp(\DateTime $when, $lat, $lon): bool {
$whenTimestamp = $when->getTimestamp();
$sunriseTimestamp = date_sunrise(
$whenTimestamp,
SUNFUNCS_RET_TIMESTAMP,
$lat,
$lon
@bramus
bramus / gist:6f0de89d49d2f2ffc07e7662613a6a68
Created August 21, 2018 12:20
Download entire website
# wget
wget -m -p -E -k www.domain.tld
# httrack
httrack http://www.domain.tld +www.domain.tld/* --path './httrack' --verbose
---
format_version: 1.1.0
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
trigger_map:
- push_branch: "*"
workflow: tests
workflows:
_tests_setup:
steps:
- activate-ssh-key: {}
@bramus
bramus / fix.md
Last active May 20, 2018 19:47
Fixing the XCode 9.x Simulator 3D/Map Performance issue

Got a slow/unresponsive Simulator with XCode 9.x?

You're most likely using some kind of 3D or Native Maps in your App then, no? Awaiting XCode 9.1 (which contains a fix) here's a workaround which replaces the bundled OpenGLES.framework with the version from XCode 9.0 beta 3.

Please do note …

⚠️ Installing frameworks/binaries from unfamiliar/untrusted resources always involves some risk. I can only say that I’ve been using the linked version without any issues. Your mileage may vary.

Instructions

{
"canvas": {
"width": 1200,
"height": 650
},
"backgrounds": [
{
"url": "https://cdn.zender.tv/live/player/thepassion/carddesigns/backgrounds/big/01.png",
"thumbnail_url": "https://cdn.zender.tv/live/player/thepassion/carddesigns/backgrounds/small/01.png",
"colors": {
@bramus
bramus / StreamResponseFactory.php
Created January 6, 2017 20:19
Glide StreamResponseFactory
<?php
use League\Flysystem\FilesystemInterface;
class StreamResponseFactory implements \League\Glide\Responses\ResponseFactoryInterface {
public function create(FilesystemInterface $cache, $path) {
return $cache->readStream($path);
}
}