Skip to content

Instantly share code, notes, and snippets.

View NV's full-sized avatar

Nikita Vasilyev NV

View GitHub Profile
@NV
NV / README.markdown
Last active March 1, 2024 11:26
AWS script to sync files with Amazon s3 and invalidate CloudFront paths that have been synced. I can't believe the AWS CLI doesn't do that in one command!

AWS s3 sync and CloudFront invalidation script

This is a scrappy script I put together to invalidate AWS CloudFront paths that have been uploaded to AWS S3.

Problem

If you host a static website on Amazon S3 and CloudFront, you need to create a CloudFront cache invalidation every time you upload files to Amazon S3.

(async function() {
let compressed_array_buffer = await compress("Hello");
console.info("compressed_array_buffer", compressed_array_buffer);
let text_decoder = new TextDecoder("utf-8", {fatal: true});
// TypeError: Failed to execute 'decode' on 'TextDecoder': The encoded data was not valid.
let compressed_text = text_decoder.decode(compressed_array_buffer);
console.info("GZIP", compressed_text);
@NV
NV / Readme.md
Last active May 28, 2023 20:42
Prepend the debugger statement to a function as easy as stopBefore('Element.prototype.removeChild'). Works in Chrome DevTools and Safari Inspector, doesn’t work in Firebug‘s and Firefox Developer Tools‘ console (I don’t know why). Works as a standalone script everywhere.

stopBefore.js

2min screencast

Examples

stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')
@NV
NV / exclude
Created October 29, 2009 11:00
Git global exclude file
# git config --global core.excludesfile /usr/local/git/exclude/exclude
# see http://groups.google.com/group/peepcode/browse_thread/thread/fe6f9c1fc9d6e725
# Rivals
.svn
.hg
# Archives
*.zip
*.gz
@NV
NV / converter.js
Last active May 18, 2021 09:22
Angular.js temperature converter sample app http://bl.ocks.org/NV/5291cc85b1f04e4be988
var app = angular.module('converter', []);
app.controller('MainController', function($scope) {
$scope.a = 0;
});
app.directive('converter', function(converters) {
return {
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
@NV
NV / README.md
Created March 18, 2010 14:14
UserScript. Replace tabs with 2 spaces

Tab size UserJS

8 spaces for the tab character is too many. I'd prefer 2.

Supported browsers: Firefox, Google Chrome, Opera, and Safari.

beforeafter
@NV
NV / README.markdown
Created September 26, 2012 14:19
Jekyll plugin for creating an alternative view (e.g. print view) for a post
@NV
NV / clone_object_with_circular_references.js
Created November 26, 2011 18:22
Clone an Object with all its circular references. Take that jQuery.extend!
function cloneObject(object) {
return extendObject({}, object);
}
function extendObject(base, object) {
var visited = [object];
// http://en.wikipedia.org/wiki/Adjacency_list_model
var set = [{value: base}];
@NV
NV / README.md
Created April 12, 2010 11:28
JavaScript Timer class. setInterval pool. Much more powerful than prototype.js's periodicalExecuter

JavaScript Timer

Run 5 times, with one second delay between calls

t1 = new Timer(500, function(){
  console.log(this.count);
  if (this.count >= 5) {
    this.stop();
  }

});

@NV
NV / README.mdown
Created October 8, 2010 12:27
UserJS: Bugzilla attachments preview