Skip to content

Instantly share code, notes, and snippets.

@juunas11
juunas11 / Program.cs
Created February 14, 2017 18:06
Calling ASP.NET Web API protected by Azure AD from a console app
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace ConsoleApplication2
{
class Program
{
@mlocati
mlocati / win10colors.cmd
Last active April 29, 2024 20:33
ANSI Colors in standard Windows 10 shell
@echo off
setlocal
call :setESC
cls
echo %ESC%[101;93m STYLES %ESC%[0m
echo ^<ESC^>[0m %ESC%[0mReset%ESC%[0m
echo ^<ESC^>[1m %ESC%[1mBold%ESC%[0m
echo ^<ESC^>[4m %ESC%[4mUnderline%ESC%[0m
@DanielSWolf
DanielSWolf / Program.cs
Last active May 2, 2024 18:33
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@vkhorikov
vkhorikov / CustomerController.cs
Last active March 28, 2024 11:09
Handling failures and input errors in a functional way
[HttpPost]
public HttpResponseMessage CreateCustomer(string name, string billingInfo)
{
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo);
Result<CustomerName> customerNameResult = CustomerName.Create(name);
return Result.Combine(billingInfoResult, customerNameResult)
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value))
.OnSuccess(() => new Customer(customerNameResult.Value))
.OnSuccess(
@BobNisco
BobNisco / controller.js
Last active February 27, 2023 15:43
onLongPress AngularJS Directive - Great for mobile!
// Somewhere in your controllers for this given example
// Example functions
$scope.itemOnLongPress = function(id) {
console.log('Long press');
}
$scope.itemOnTouchEnd = function(id) {
console.log('Touch end');
}
@hiddentao
hiddentao / gist:7300694
Last active January 22, 2019 05:04
An improvement on the angular.module() API, making it easier to split up modules into multiple files without having to worry about only registering them once.
/**
* Workaround to make defining and retrieving angular modules easier and more intuitive.
*/
(function(angular) {
var origMethod = angular.module;
var alreadyRegistered = {};
/**
@CMCDragonkai
CMCDragonkai / angularjs_directive_attribute_explanation.md
Last active November 29, 2023 15:35
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@thomseddon
thomseddon / gist:3511330
Last active March 8, 2023 03:39
AngularJS byte format filter
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});