Skip to content

Instantly share code, notes, and snippets.

View krist00fer's full-sized avatar

Kristofer Liljeblad krist00fer

View GitHub Profile
@krist00fer
krist00fer / httpGetJSON.js
Created October 29, 2014 00:11
Make HTTP GET Request and retrieve data as a JSON Object
var http = require('http');
function httpGetJSON(url, callback) {
http.get(url, function(res) {
var body = '';
res.on('data', function(data) {
console.log('httpGetJSON - data received', data);
body += data;
});
@krist00fer
krist00fer / blink.js
Created October 29, 2014 00:14
Blink led on Tessel device a specific amount of times
@krist00fer
krist00fer / pad.js
Last active August 29, 2015 14:08
Add leading zeros (character or string) to number
// Pad number i left with c until n characters or more
// padLeft(1, 3); // '001'
// padLeft(12, 3); // '012'
// padLeft(1234, 3); // '1234'
// padLeft(1, 3, 'x'); // 'xx1'
function padLeft(i, n, c){
return Array(n - String(i).length + 1).join(c||'0') + i;
}
@krist00fer
krist00fer / Point.cs
Last active August 29, 2015 14:09
What's New in C# 6.0?
namespace CSharp6
{
// What's New In C# 6.0?
//
// The following class and the implementation was created as a personal reference after
// watching Mads Torgersen's video. Most of this example is from him.
//
// - What's New In C# 6.0 (http://channel9.msdn.com/Events/Visual-Studio/Connect-event-2014/116)
//
// Features
@krist00fer
krist00fer / app.js
Last active August 29, 2015 14:10
Sliding window epiration of keys in Redis
// Prerequisites:
// npm install redis
var redis = require('redis');
var client = redis.createClient();
client.setex('fixedexpkey', 5, 'Foo');
client.setex('slidingexpkey', 5, 'Bar');
// Get value every second without using a sliding window expiration implementation
@krist00fer
krist00fer / appendblob.cs
Created October 15, 2015 14:26
Sample program on how to use Azure Append Blob. Perfect for "ever growing" files like: log-files, etc.
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using System;
namespace AppendBlobSample
{
class Program
{
private static string StorageAccountName = "put-your-storage-account-name-here";
private static string StorageAccountAccessKey = "put-your-storage-account-access-key-here";
@krist00fer
krist00fer / Get-AzureUsageCost.ps1
Last active May 8, 2024 16:39
PowerShell Script to retrieve Azure Usage and Cost/Pricing
# Licensed under the MIT license.
# Copyright (C) 2017 Kristofer Liljeblad
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@krist00fer
krist00fer / Program.cs
Created May 7, 2020 08:36
Equivalent comparison using FluentAssertions
using FluentAssertions;
using System;
using System.Collections.Generic;
namespace CompareTest
{
class Program
{
static void Main(string[] args)
{