Skip to content

Instantly share code, notes, and snippets.

View James-E-Adams's full-sized avatar
Powered by cold brew and stress.

James Adams James-E-Adams

Powered by cold brew and stress.
View GitHub Profile
@quad
quad / Code.gs
Created October 28, 2020 03:50
Block out my work calendar with my personal events
function hashify(hash, [key, value]) {
hash[key] = value;
return hash;
}
function eventId(event) {
if (event.isRecurringEvent()) {
return event.getId() + "-" + event.getStartTime().toISOString() + "-" + event.getEndTime();
}

Boolean() or !! (double bang, double negation)?

What's the best way to answer the question "true or false?" in JavaScript

JavaScript does not bother you too much with types (at first), which is both a blessing and a cure. But we all know the Boolean type. Boolean variables can either be true or false. Yes or no.

Every value in JavaScript can be translated into a boolean, true or false. Values that translate to true are truthy, values that translate to false are falsy. Simple.

This is about two ways to make that translation.

@bvaughn
bvaughn / LICENSE.md
Last active November 9, 2023 07:13
Advanced example for manually managing subscriptions in an async-safe way using hooks

The MIT License (MIT)

Copyright © <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

@rossharper
rossharper / ParameterizedKotlinTest.kt
Created February 20, 2016 21:51
Parameterized JUnit4 test example in Kotlin
@RunWith(Parameterized::class)
class KotlinTest(val paramOne: Int, val paramTwo: String) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data() : Collection<Array<Any>> {
return listOf(
arrayOf(1, "I"), // First test: (paramOne = 1, paramTwo = "I")
arrayOf(1999, "MCMXCIX") // Second test: (paramOne = 1999, paramTwo = "MCMXCIX")
@hallem
hallem / RestSharp_FileAsBody.cs
Last active October 13, 2022 16:48
RestSharp file as body
public RestApiResponse<bool> PutEnvelopesDocuments(string envelopeId, string documentId, string fullFileName, byte[] documentBytes)
{
RestRequest request = GetBaseRequest("envelopes/{envelopeId}/documents/{documentId}", Method.PUT);
request.AddUrlSegment("envelopeId", envelopeId);
request.AddUrlSegment("documentId", documentId);
request.AddHeader("Content-Type", "application/pdf");
request.AddHeader("Content-Disposition",
string.Format("file; filename=\"{0}\"; documentid={1}; fileExtension=\"{2}\"",
Path.GetFileNameWithoutExtension(fullFileName), documentId, Path.GetExtension(fullFileName)));
@Anmo
Anmo / example.sh
Last active May 30, 2024 13:04
Use of submodules and sparse-checkout
#!/bin/bash
#First create a repo
mkdir A && cd A && git init && touch a.dev && touch a.prod && git add -A && git commit -m 'init A' && cd ../
#Lets create another repo that will use A as submodule with sparse-checkout
mkdir B && cd B && git init && touch b && git add -A && git commit -m 'init B'
#Now we will clone A as submodule of B and will say that file/dir we only want to use in B
git submodule add ../A/ A && cd A && git config core.sparsecheckout true && echo a.prod >> ../.git/modules/A/info/sparse-checkout && git read-tree -mu HEAD && cd ../ && git add -A && git commit -m 'add A as submodule/sparse-checkout' && cd ../
@ndarville
ndarville / diff.mdown
Created July 23, 2012 20:33
Paul Heckel's Diff Algorithm

[Isolating Differences Between Files][paper]

Advantage over Other Algorithms

The diff output is more specific:

[I]f a whole block of text is moved, then all of it, rather than just the beginning and end, is detected as changed.

>The algorithm described here avoids these difficulties. It detects differences that correspond very closely to our intuitive notion of difference.