Skip to content

Instantly share code, notes, and snippets.

View Baudin999's full-sized avatar

Baudin999 Baudin999

  • Netherlands
View GitHub Profile
@Baudin999
Baudin999 / gist:7682768
Created November 27, 2013 20:35
Chrome App Storage, retrieving and saving
// When getting somehting from the chrome storage you
// need to keep in mind that these items are returned
// as objects compared to the localStorage in the browser
// which returns the items als string literals.
// In combination with angularJS you need to keep in mind
// that you need to apply the result of this async call
// the the $scope of the controller. This will trigger
// the refresh.
@Baudin999
Baudin999 / blog_$_img_rotator_ext
Last active December 29, 2015 15:09
jQuery image rotator extension
// a jQuery extension for an image rotator with options
(function ($) {
$.fn.rotate = function (options) {
// initialize the options object if it's null.
var o = options || { images: [] },
that = this,
index = 0,
length = o.images.length;
if (!o.images) o.images = [];
@Baudin999
Baudin999 / blog_simplelogger
Created November 28, 2013 07:35
A Simple logger for a Windows Service
using System;
using System.IO;
using System.Web;
namespace test01
{
public static class Logger
{
public static void Log(string message)
@Baudin999
Baudin999 / gist:7704720
Created November 29, 2013 11:58
Set an async value in AngularJS
// imagine a factory with the following code somewhere in the factory:
app.factory('asyncFactory', function($q, $timeout) {
// a factory always needs to return a value
return {
getAsyncValue: function () {
var deferred = $q.defer();
$timeout(function () {
deferred.resolve('This is an item');
}, 2000);
return deferred.promise;
@Baudin999
Baudin999 / gist:8399871
Created January 13, 2014 13:01
Add routes to angularJS's $routeProvider where rpv is a variable (pointer) to the actual routeprovider
app.run(function ($http) {
$http.get('/api/menu').then(function (routes) {
routes.data.forEach(function (route) {
rpv.when(route, {
controller: '<controller name>',
templateUrl: '<tempalte name>',
reloadOnSearch: false
});
});
});
@Baudin999
Baudin999 / notifyPropertyChanged
Created June 16, 2014 10:13
Notify property changed
define(function () {
var self = this;
self.notifyPropertyChanged = function (obj) {
// initialize the local variables
var args = Array.prototype.slice.call(arguments),
skipList = [];
@Baudin999
Baudin999 / gist:2a30a6e6dd6fb849696e
Created June 26, 2015 13:15
A small promise lib
/// Promise.js
function Promise() {
this.then = function (handler) {
this.thenHandler = handler;
return this;
};
this.error = function (handler) {
@Baudin999
Baudin999 / functional_programming
Created January 9, 2016 13:16
Functional Programming
Table of contents:
[TOC]
Functional Programming
===================
Why are we so fussed about Functional Programming? Is it really better than Object Oriented programming? Can it solve our problems?
If you are like me you'll have heard a lot of buzz about functional programming these last few years you might be wondering how this "functional programming" fits into your day to day work and how it affects your code.
The answer is quite simple, yes, functional programming will make you a better programmer. Yes, functional programming will solve a lot of problems arising from complexity; but most of all functional programming is the only way to leverage the power of multi-core chip-sets.
@Baudin999
Baudin999 / Process F# Monad
Created March 21, 2016 11:51
A simple Process MOnad in F#
type Process<'a> =
| Value of 'a
| Message of string
let quad a = a * a
let add a b = a + b
let print m =
match m with
| Value n -> printf "Number: %d\n" n
@Baudin999
Baudin999 / gist:fa694b1a402fb982f708f92042535cab
Created June 3, 2016 13:22
JSFiddle console.log override:
document.getElementById('element').innerHTML = "";
console.log = function(...m) {
document.getElementById('element').innerHTML += m.reduce((_m, _a) => _m + _a, "");
document.getElementById('element').innerHTML += "<br />";
}