Skip to content

Instantly share code, notes, and snippets.

View VivienAdnot's full-sized avatar

Vivien Adnot VivienAdnot

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<VAST version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd">
<Ad id="1">
<Wrapper>
<AdSystem>xx</AdSystem>
<VASTAdTagURI>
<![CDATA[https://pubads.g.doubleclick.net/gampad/ads?sz=450x400...]]>
</VASTAdTagURI>
<Extensions>
<Extension type="waterfall" fallback_index="0" />
@VivienAdnot
VivienAdnot / grep_logs.sh
Last active October 21, 2016 09:50
parse video logs to extract stats
#!/bin/bash
function init() {
touch result.txt
grep "tracker.gif" iis.log > tracker.log
}
function createTitle() {
echo " " >> result.txt
echo "==============================" >> result.txt
@VivienAdnot
VivienAdnot / asyncify.js
Created October 7, 2016 12:14
how to transform a sync function that returns a value or throws an exception, as async that fires a callback
function asyncify(f) {
return function _asyncify() {
var args = Array.prototype.slice.call(arguments, 0);
var argsWithoutLast = args.slice(0, -1);
var callback = args[args.length - 1];
var result, error;
try {
result = f.apply(this, argsWithoutLast);
} catch (e) {
it('should simulate promise', inject(function($q, $rootScope) {
var deferred = $q.defer();
var promise = deferred.promise;
var resolvedValue;
promise.then(function(value) { resolvedValue = value; });
expect(resolvedValue).toBeUndefined();
// Simulate resolving of promise
deferred.resolve(123);
@VivienAdnot
VivienAdnot / MainCtrl.js
Created September 14, 2016 04:43
Angular Promises Unit test
angular.module('breakmeApp')
.controller('MainCtrl', function($scope, searchService) {
searchService.search($scope.query)
.then(function(data) {
// This is set when the promise is resolved.
$scope.results = data;
})
.catch(function() {
// This is set in the event of an error.
$scope.error = 'There has been an error!';
@VivienAdnot
VivienAdnot / Promises - fetch => sum ES5.js
Last active August 31, 2016 09:37
Play with promises: call several endpoints and aggregate the result
var data = [{
isActive: "1",
logins: 2000,
clicks: 1000
}, {
isActive: "1",
logins: 3000,
clicks: 1000
}, {
isActive: "1",
@VivienAdnot
VivienAdnot / once.js
Created July 5, 2016 15:43
call the function once, the other times it won't be called
function once(fn) {
var returnValue, called = false;
return function () {
if (!called) {
called = true;
returnValue = fn.apply(this, arguments);
}
return returnValue;
};
}
@VivienAdnot
VivienAdnot / Gruntfile.js
Created April 21, 2016 14:25
A gruntfile example with livereload
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
@VivienAdnot
VivienAdnot / stream.js
Created January 15, 2016 09:20
stream head tail
function node(head, tail) {
return [head, tail];
};
function head(stream) {
return stream[0];
};
function tail(stream) {
var tail = stream[stream.length - 1];
@VivienAdnot
VivienAdnot / checkValidateObject.js
Created October 30, 2015 13:57
To ensure that an objects matches the expected structure
var target = {
prop1: "123",
prop2: "456",
prop3: {
A: "1",
B: "2"
}
};
var schema = [