Skip to content

Instantly share code, notes, and snippets.

View apaatsio's full-sized avatar

Antti Ahti apaatsio

View GitHub Profile
@apaatsio
apaatsio / assert.dart
Last active October 1, 2018 10:26
lcov report shows coverage only for some asserts in Flutter 0.8.2; https://github.com/flutter/flutter/issues/22508
void successfulAsserts(int x) {
assert(true);
assert(x != null);
assert(x == 1);
int foo = 1;
assert(foo == 1);
}
void failingAssert() {
assert(false);
{
"sourceSpace": "XXX",
"destinationSpace": "YYY",
"sourceDeliveryToken": "AAA",
"managementToken": "ZZZ",
"syncTokenDir": "/tmp/contentful-sync",
"rateLimit": 1,
"rateLimitPeriod": 5000
}
@apaatsio
apaatsio / kitten_in_console.js
Created October 31, 2016 15:31
JavaScript snippet to show random kitten image in console
(function(url) {
// Create a new `Image` instance
var image = new Image();
image.onload = function() {
// Inside here we already have the dimensions of the loaded image
var style = [
// Hacky way of forcing image's viewport using `font-size` and `line-height`
'font-size: 1px;',
'line-height: ' + this.height + 'px;',
@apaatsio
apaatsio / apple_i_products_regex.js
Created October 25, 2016 14:04
Useless regexp to match Apple i products
/i(?:P(?:hone|od|ad)|Book|Mac|Cloud)/.exec("Apple iPhone 7")
@apaatsio
apaatsio / graphql_test.md
Last active October 21, 2016 05:59
Github GraphQL test
@apaatsio
apaatsio / openstack_kubernetes_dev.md
Created October 3, 2016 20:35
Setting up OpenStack + Kubernetes dev environment

Instructions to setup OpenStack + Kubernetes development environment on VirtualBox

Total time for the setup is about 45 minutes but most of it is waiting packages to download and install.

  1. Download Ubuntu and install it on VirtualBox (20min)

  2. Start the Ubuntu (1min)

  3. Install git (1min)

     sudo apt install git
    
  4. Follow instructions on http://docs.openstack.org/developer/devstack/ (20min)

@apaatsio
apaatsio / dynamodb-rest-api-lambda.js
Last active September 13, 2019 16:13
Single Lambda function for all CRUD operations with DynamoDB in REST API
console.log('Loading function');
var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();
/**
* Provide an event that contains the following keys:
*
* - operation: one of the operations in the switch statement below
* - tableName: required for operations that interact with DynamoDB
@apaatsio
apaatsio / gulp.log
Created December 1, 2014 12:12
gulp watch ENOENT error (gulp 3.8.10)
Error: watch ENOENT
at errnoException (fs.js:1030:11)
at FSWatcher.start (fs.js:1062:11)
at Object.fs.watch (fs.js:1087:11)
at Gaze._watchDir (/home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:289:30)
at /home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:358:10
at iterate (/home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:52:5)
at /home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:61:11
at /home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:420:5
at iterate (/home/antti/work/web/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:52:5)
@apaatsio
apaatsio / reaktor_fast_track.js
Last active December 22, 2015 06:58
Solution for Reaktor's programming task at http://reaktor.fi/ura/fast_track/ This solution relies on the fact that JavaScript can solve multiplication for strings (e.g. "2" * "3" -> 6) and thus parseInt is not needed.
function (input) {
function product(numbers) {
if (numbers.indexOf("0") !== -1) {
return 0
} else {
return _(numbers).reduce(function(product, number){
return product * number
}, 1)
}
}
@apaatsio
apaatsio / caller.coffee
Created July 17, 2013 09:52
Load JavaScript functions synchronously just-in-time. This is just a concept. This is not ready and I haven't even tried running this.
myObject =
myFunction: loadFunction 'myModule/myFunction', this