Skip to content

Instantly share code, notes, and snippets.

@searls
searls / 001_functions_and_views.sql
Created December 29, 2020 13:32
KameSame's December 2020 search overhaul
-- This all starts with some functions and a *materialized* postgres view that unnests several
-- arrays of strings of definitions into flattened rows that are easier to search. Fun fact:
-- you can even create indexes on materialized views' columns! They'll refresh whenever the view
-- is refreshed (which in my case is every time that we pull new dictionary data from WaniKani or JMDICT
-- This function will take an array of strings and convert all the double-width alphanumeric characters
-- and normalize them as half-width. That way a search query can be massaged from "OK" to "ok" easily
CREATE OR REPLACE FUNCTION array_hankakufy_romaji(character varying[])
RETURNS character varying[]
AS
@existentialmutt
existentialmutt / Ruby.sublime-syntax
Last active February 19, 2022 21:49
Enhancing Sublime Ruby syntax highlighting with ERB and HAML embedded in heredocs
%YAML 1.2
---
name: Ruby (Custom)
# TODO: unresolved issues
#
# text:
# "p << end
# print me!
# end"
# symptoms:
@manoj-choudhari-git
manoj-choudhari-git / WSL_Install.ps1
Last active April 21, 2024 15:44
PowerShell script to install WSL 2
# STEP 1: Enable Virtual Machine Platform feature
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# STEP 2: Enable WSL feature
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# STEP 3: Restart Win 10 Machine
# STEP 4: To set the WSL default version to 2.
# Any distribution installed after this, would run on WSL 2
@pcreux
pcreux / README.md
Last active October 10, 2020 18:44
Failsafe: degrade user experience and notify when something goes wrong.

Failsafe

When something goes wrong I want to degrade the user experience (instead of returning a 500 - Server Error) And I want to be notified about the failure

Usage

Wrap non mission critical code:

@kinoute
kinoute / .Dockerfile
Last active March 10, 2025 21:21
Example of Ruby on Rails 6 Multi-stage builds with Docker. Development/production environments share the same Dockerfile.
FROM ruby:2.7.1-slim AS base
LABEL maintainer="Yann Defretin <[email protected]"
# Common dependencies
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq \
--no-install-recommends \
build-essential=12.6 \
gnupg2=2.2.12-1+deb10u1 \
---
# Archive of http://www.columbia.edu/~alan/schemas/common/jsonapi.yaml
openapi: 3.0.2
info:
version: 1.0.0
title: "{json:api} Specification"
description: >
An include file to define the [{json:api} 1.0 specification](http://jsonapi.org/format).
N.B. I've got some confusion going on between a validating a jsonapi schema and defining one!
@pixeltrix
pixeltrix / sonar.rb
Last active May 9, 2020 21:53
Ruby implementation of the NHS contact tracing app's messages and how they're decrypted
require "openssl"
require "securerandom"
##########################
### iOS/Android Device ###
##########################
# Installation id - returned by the registration request
uuid = "E1D160C7-F6E8-48BC-8687-63C696D910CB"
uuid_bytes = uuid.scan(/[0-9A-Z]{2}/).map { |s| s.to_i(16) }.pack("C*")
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active July 6, 2025 20:56
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@praveen001
praveen001 / authorizer.go
Last active September 17, 2024 01:27
Serverless WebSockets with API Gateway and Golang Lambda
// Authorizer custom api authorizer
func Authorizer(request APIGatewayWebsocketProxyRequest) (events.APIGatewayCustomAuthorizerResponse, error) {
token := request.QueryStringParameters["token"]
// Fetch all keys
jwkSet, err := jwk.Fetch("https://cognito-idp.ap-south-1.amazonaws.com/ap-south-1_vvx4f42sK/.well-known/jwks.json")
if err != nil {
log.Fatalln("Unable to fetch keys")
}
@naesean
naesean / jsonapi_oas.yml
Last active May 9, 2025 06:06
OpenAPI 3.0 schemas that comply with the JSON:API 1.0 specification
JSONAPIObject:
description: Includes the current JSON:API version for this specification as well as optional meta information
type: object
required:
- version
properties:
version:
type: string
default: '1.0'
example: '1.0'