Skip to content

Instantly share code, notes, and snippets.

@AzrizHaziq
AzrizHaziq / I18n.ts
Last active March 31, 2023 19:33
JS & TS
// https://kentcdodds.com/blog/listify-a-java-script-array
// unfortunately TypeScript doesn't have Intl.ListFormat yet 😢
// so we'll just add it ourselves:
type ListFormatOptions = {
type?: 'conjunction' | 'disjunction' | 'unit'
style?: 'long' | 'short' | 'narrow'
localeMatcher?: 'lookup' | 'best fit'
}
declare namespace Intl {
class ListFormat {
@dylanmckay
dylanmckay / facebook-contact-info-summary.rb
Last active March 12, 2024 22:46
A Ruby script for collecting phone record statistics from a Facebook user data dump
#! /usr/bin/env ruby
# NOTE: Requires Ruby 2.1 or greater.
# This script can be used to parse and dump the information from
# the 'html/contact_info.htm' file in a Facebook user data ZIP download.
#
# It prints all cell phone call + SMS message + MMS records, plus a summary of each.
#
# It also dumps all of the records into CSV files inside a 'CSV' folder, that is created
@claudiopro
claudiopro / .gitignore
Last active November 10, 2017 20:24 — forked from rauchg/README.md
require-from-dat
/node_modules/
module.js
@asciidisco
asciidisco / drm_idk.md
Last active October 20, 2021 07:32
EME? CDM? DRM? CENC? IDK!

Title

EME? CDM? DRM? CENC? IDK!

Abstract

Once there was the <video/> tag, but content distributors decided it wasn't enough. They wanted more - more power, more protection, more control, more features. So, Encrypted Media Extensions were born & Digital Rights Management appeared in our browsers.

@getify
getify / 1.js
Last active June 2, 2021 15:41
Proposal: curried function declarations in javascript -- aka, making FP development in JS much much nicer
// Standard:
function fn(x) {
return function(y){
return function(z){
return x * y / z;
};
};
}
@FQ400
FQ400 / braching.js
Last active September 15, 2017 07:42
Branching in functional javascript using Ramda
import R from 'ramda';
const payloadSizeWithinLimit = (payload, limit) => limit > payload.size;
const errorState = { name: 'can not be empty' };
const sizeInBytes = 50000;
let errorObj;
errorObj = R.cond([
[R.equals(true), R.always({})],
@epatr
epatr / _reboot-variables.scss
Created June 14, 2017 22:51
A Sass file to @import before importing Bootstrap 4's Reboot file. Uses Bootstrap defaults.
// Required mixin
$enable-hover-media-query: false;
@mixin hover-focus {
@if $enable-hover-media-query {
&:focus { @content }
@include hover { @content }
}
@else {
&:focus,
&:hover {
@ithinkihaveacat
ithinkihaveacat / service-worker.d.ts
Last active February 25, 2024 02:30 — forked from tiernan/service-worker.d.ts
Typings for using the Service Worker API with TypeScript
/**
* Copyright (c) 2016, Tiernan Cridland
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
* granted, provided that the above copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@tiernan
tiernan / service-worker.d.ts
Last active February 20, 2022 11:04
Typings for using the Service Worker API with TypeScript
/**
*
* DEPRECIATED: Please use the updated type definitions:
* Service Worker Typings to Supplement lib.webworker.d.ts
* https://gist.github.com/tiernan/c18a380935e45a6d942ac1e88c5bbaf3
*
*
* Copyright (c) 2016, Tiernan Cridland
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
@joshdover
joshdover / README.md
Last active September 28, 2023 21:38
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed: