Skip to content

Instantly share code, notes, and snippets.

View carlcraig's full-sized avatar
🦄
Working

Carl Craig carlcraig

🦄
Working
View GitHub Profile
@Wallacy
Wallacy / apollo.ts
Last active January 29, 2023 16:33
Apollo Server + Cloudflare Workers
import { ApolloServerBase, Config, gql } from 'apollo-server-core'
export class ApolloServer extends ApolloServerBase {
protected override serverlessFramework(): boolean {
return true
}
public async createHandler() {
await this.ensureStarted()
return async (request: Request) => {
@unicornware
unicornware / algolia.ts
Last active May 19, 2023 10:57
Jest Mocks - Algolia
import { createWaitablePromise as waitable } from '@algolia/client-common'
import type {
ChunkedBatchResponse,
DeleteResponse,
SearchResponse,
SetSettingsResponse,
Settings
} from '@algolia/client-search'
import type { SearchIndex } from 'algoliasearch'
import type { PlainObject } from 'simplytyped'
@robertgonzales
robertgonzales / App.jsx
Last active March 26, 2020 15:57
How to make a custom Prompt (using getUserConfirmation) for React Router v4
// use Prompt like normal... magic happens in getUserConfirmation
class App extends Component {
render () {
return (
<Router getUserConfirmation={getUserConfirmation}>
{...}
<Prompt
when={formIsHalfFilledOut}
message="Are you sure you want to leave?"
/>
@Rich-Harris
Rich-Harris / service-workers.md
Last active July 10, 2024 17:04
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@markerikson
markerikson / appEntryPoint.js
Last active August 1, 2022 07:41
Webpack React/Redux Hot Module Reloading (HMR) example
import React from "react";
import ReactDOM from "react-dom";
import configureStore from "./store/configureStore";
const store = configureStore();
const rootEl = document.getElementById("root");
@soerenbernstein
soerenbernstein / RevisionsCleanupCommand.php
Created April 21, 2016 06:36
Revisions cleanup for SimpleThings/EntityAudit as symfony command
<?php
/**
* Created by PhpStorm.
* User: Sören Bernstein
* Date: 15.09.2015
* Time: 12:57
*/
namespace Redlink\CASBundle\Command;
@ygotthilf
ygotthilf / jwtRS256.sh
Last active July 28, 2024 08:52
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@marcoslin
marcoslin / app.js
Last active October 8, 2021 08:52
Simple angularAMD Sample
define(['angularAMD', 'angular-route'], function (angularAMD) {
var app = angular.module("webapp", ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when("/home", angularAMD.route({
templateUrl: 'view_home.html', controller: 'HomeCtrl', controllerUrl: 'controller_home'
}))
.when("/view1", angularAMD.route({
templateUrl: 'view_view1.html', controller: 'View1Ctrl', controllerUrl: 'controller_view1'
@mauris
mauris / queue-ensure.php
Created April 28, 2014 15:44
Laravel Artisan Queue Ensurer - Set a cron job to run this file periodically to ensure that Laravel's queue is processing all the time. If the queue listener stopped, restart it!
<?php
function runCommand ()
{
$command = 'php artisan queue:listen > /dev/null & echo $!';
$number = exec($command);
file_put_contents(__DIR__ . '/queue.pid', $number);
}
if (file_exists(__DIR__ . '/queue.pid')) {
@Divi
Divi / compile-php-thread-safe-and-pthreads.sh
Last active May 19, 2021 00:43
Compile PHP Thread Safe & pthreads extension
#!/usr/bin/env bash
# PARAMETERS
# ----------
# PHP
# ---
PHP_TIMEZONE="UTC"
PHP_DIRECTORY="/etc/php5ts"