Skip to content

Instantly share code, notes, and snippets.

@rwaldron
rwaldron / find.md
Last active December 14, 2015 11:28
ES6 Array.prototype.find spec

15.4.4.x Array.prototype.find ( predicate [ , thisArg ] )

predicate should be a function that accepts three arguments and returns a value that is coercible to the Boolean value true or false. find calls predicate once for each element present in the array, in ascending order, until predicate returns true and immediately returns the current array element. Otherwise, find returns null. predicate is called only for elements of the array which actually exist; it is not called for missing elements of the array.

  1. Let O be the result of ToObject passing the this value as the argument.
  2. ReturnIfAbrupt( O ).
  3. Let lenValue be the result of Get( O, "length" ).
  4. Let len be ToUint32( lenValue ).
  5. ReturnIfAbrupt( len ).
  6. If len is 0, return undefined.
@rwaldron
rwaldron / findindex.md
Last active December 14, 2015 11:29
ES6 Array.prototype.findIndex spec

15.4.4.x Array.prototype.findIndex ( predicate [ , thisArg ] )

predicate should be a function that accepts three arguments and returns a value that is coercible to the Boolean value true or false. findIndex calls predicate once for each element present in the array, in ascending order, until predicate returns true and immediately returns the index of the current array element. Otherwise, findIndex return -1. predicate is called only for elements of the array which actually exist; it is not called for missing elements of the array.

  1. Let O be the result of ToObject passing the this value as the argument.
  2. ReturnIfAbrupt( O ).
  3. Let lenValue be the result of Get( O, "length" ).
  4. Let len be ToUint32( lenValue ).
  5. ReturnIfAbrupt( len ).
  6. If len is 0, return -1.
@yamanetoshi
yamanetoshi / XWalkViewExample.java
Created July 27, 2015 06:55
XWalkView Example
mWebView.setResourceClient(new XWalkResourceClient(mWebView) {
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
WebResourceResponse ret = null;
try {
URL tmpUrl = new URL(url);
mConn = (HttpURLConnection)tmpUrl.openConnection();
mConn.addRequestProperty("Authorization", authHeader);
mConn.addRequestProperty(getString(R.string.app_version_header_key), ((MyApplication)getApplication()).getVersioName());
@robertknight
robertknight / reviewing-dependency-updates.md
Last active February 3, 2020 20:42
How I review dependency updates

How I review dependency updates

These are some notes on my process when I review dependency updates for both JavaScript and Python projects at Hypothesis.

Before you add a dependency

Before adding a dependency to a project, consider the impact on future maintenance. If what the dependency does for the project can be implemented with only a few lines of code, or can be implemented in an alternative way using dependencies the project already has, it may be a better choice to do that and avoid the dependency.

Dependency update process

@joakimbeng
joakimbeng / test_runner.js
Last active July 12, 2020 22:38
A small and simple Javascript test runner
/**
* A Javascript test runner in 20 lines of code
* From http://joakimbeng.eu01.aws.af.cm/a-javascript-test-runner-in-20-lines/
*/
(function () {
// The test queue:
var tests = [];
// Function to add tests:
this.test = function test (name, cb) {
@alano999
alano999 / README.md
Created September 15, 2012 15:12
Sequence (chain) multiple asynchronous jQuery operations, such as AJAX

MULTIPLE SEQUENTIAL ASYNCHRONOUS OPERATIONS IN JQUERY

Multiple asynchronous jQuery operations such as .ajax() and animations can be sequenced (chained) using the accompanying patterns which make use of jQuery Deferred techniques rather than the less extensible and non-ideal recursive call techniques.

There are three usage patterns, each implemented herein and tested using the supplied data for .ajax() transactions...

  1. Sequential in series using pre-defined data;
  2. Sequential in series, feeding each request using the response from previous request;
  3. Parallel request using pre-defined data, where responses are sequenced.
@simonkuhn
simonkuhn / geo.vcl
Last active January 7, 2022 12:16
Fastly VCL for geoip json output
sub vcl_recv {
#FASTLY recv
# We don't do other methods
if (req.method != "GET") {
return(error);
}
# Handle IPv4 or IPv6 provided in url path (nothing extraneous allowed, perform basic matching)
if (req.url.path ~ "^/([a-f0-9:.]+)$") {
set client.geo.ip_override = re.group.1;
@berzniz
berzniz / jshipster_and_and.js
Last active May 22, 2022 23:15
Some small javascript hacks for hipsters
// Boring
if (isThisAwesome) {
alert('yes'); // it's not
}
// Awesome
isThisAwesome && alert('yes');
// Also cool for guarding your code
var aCoolFunction = undefined;
@weakish
weakish / README.markdown
Last active December 18, 2023 05:58
#Solarized themes (dark and light) for #roxterm.
@marteinn
marteinn / info.md
Last active January 21, 2024 06:57
Using the Fetch Api with Django Rest Framework

Using the Fetch Api with Django Rest Framework

Server

First, make sure you use the SessionAuthentication in Django. Put this in your settings.py

# Django rest framework
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
 'rest_framework.authentication.SessionAuthentication'