Skip to content

Instantly share code, notes, and snippets.

View niieani's full-sized avatar

Bazyli Brzóska niieani

View GitHub Profile
@niieani
niieani / throttle-and-debounce.sh
Last active December 11, 2023 15:39
throttle and debounce commands in bash
#!/usr/bin/env bash
declare -i last_called=0
declare -i throttle_by=2
@throttle() {
local -i now=$(date +%s)
if (($now - $last_called >= $throttle_by))
then
"$@"
@niieani
niieani / no_automount.bash
Created August 18, 2022 05:16
Prevent an external drive from auto mounting on macOS
#!/usr/bin/env bash
# Taken from: https://akrabat.com/prevent-an-external-drive-from-auto-mounting-on-macos/
# Usage: ./no_automount My\ Disk
NAME=$1
if [ -z "$NAME" ] ; then
echo "Usage: no_automount {Disk Name}"
exit 1
@niieani
niieani / gist:1213709
Created September 13, 2011 12:33
PHP Camel Case functions
<?php
// source: http://www.paulferrett.com/2009/php-camel-case-functions/
/**
* Translates a camel case string into a string with underscores (e.g. firstName -&gt; first_name)
* @param string $str String in camel case format
* @return string $str Translated into underscore format
*/
function from_camel_case($str) {
$str[0] = strtolower($str[0]);
@niieani
niieani / laika-example.ts
Last active November 11, 2021 00:37
Laika intercepts are similar to mock functions
it('mocks the rocket launches once', () => {
// the `laika` variable below can come either from the global instance, when running in the browser
// or in case of unit tests, it might be a link we've set up in a `beforeAll` of this test suite
const interceptor = laika.intercept({ operationName: 'ListMissions' })
interceptor.mockResultOnce({
result: {
data: {
launchesPast: [
{ mission_name: 'Sputnik 2', launch_site: { site_name_long: 'Baikonur 1/5' } },
@niieani
niieani / laika-example.ts
Created November 11, 2021 00:25
An example Cypress test using Laika's Subscription mocking
import type {Laika, InterceptApi} from '@zendesk/laika'
describe('My suite', () => {
let laika: Laika
before(() => {
cy.visit('/')
cy.window()
.its('laika')
.then((instance) => {
@niieani
niieani / laika-example.ts
Created November 10, 2021 22:48
Loading Laika in production code conditionally
import { createLazyLoadableLaikaLink } from '@zendesk/laika'
const conditionalLinks = window.Cypress
? [createLazyLoadableLaikaLink({ clientName: 'my-graph' })
: []
const apolloClient = new ApolloClient({
link: ApolloLink.from([
...conditionalLinks,
new HttpLink({ uri: 'https://api.example.com/graphql' }),
@niieani
niieani / lighthouse+8.5.1.patch
Last active October 12, 2021 07:49
Add networkIdleIgnoredUrlPatterns to Lighthouse
diff --git a/lighthouse-core/config/constants.js b/lighthouse-core/config/constants.js
index 264402bb026484a293a9efac60405c52eb8f525b..4aa5098162b70d83ed4ba6c630894ebaf27908a9 100644
--- a/lighthouse-core/config/constants.js
+++ b/lighthouse-core/config/constants.js
@@ -114,6 +114,7 @@ const defaultSettings = {
budgets: null,
locale: 'en-US', // actual default determined by Config using lib/i18n
blockedUrlPatterns: null,
+ networkIdleIgnoredUrlPatterns: null,
additionalTraceCategories: null,
@niieani
niieani / app.html
Last active September 7, 2021 13:54 — forked from jdanyow/app.html
Aurelia RequireJS Gist
<template>
<!-- Simple usage: -->
<h1>message: ${async(message).value}</h1>
<!-- With a placeholder: -->
<h1>message: ${async(message).value ? async(message).value : '...'}</h1>
</template>
@niieani
niieani / utils.ts
Created November 26, 2017 12:20
TypeScript utils
// many based/copied from https://github.com/tycho01/typical/tree/master/src
// utility types:
type False = "0";
type True = "1";
type Bool = True | False;
type If<Cond extends Bool, Then, Else> = { 1: Then; 0: Else }[Cond];
type WrapInPromiseIfTrue<T, IsAsync extends Bool> = If<
IsAsync,
Promise<T>,
@niieani
niieani / google-photos.user.css
Created July 9, 2019 20:11
Remove top gradient in Google Photos
/* ==UserStyle==
@name Remove top gradient in Google Photos - 09/07/2019, 22:08:26
@namespace github.com/niieani
@version 1.0.0
@description Removes the annoying top gradient in the Google Photos views: full screen photo, album
@author Bazyli Brzóska
==/UserStyle== */
@-moz-document domain("photos.google.com") {
.KYCEmd {
background-image: none;