Skip to content

Instantly share code, notes, and snippets.

View HTTPPostCachingPolicy.xml
<!-- Custom caching policy for on HTTP POST for Azure API Management:
1. Policy looks in the Request body - 'cacheKey' property which then used as cache key.
Expected values are: <null>, ALL or NOEXPIRED
Defaults to ALL in case <null>
2. Cache expiration set to 60 seconds/1 minute
!-->
<policies>
<inbound>
<base />
View router-wrapper.js
const debug = require('./debug.config')('app:router-wrapper', console)
const wrapMethod = function (router, method) {
if (typeof router[method] !== "function") return false;
const original = router[method].bind(router);
debug('patching method: %o', method)
router[method] = (...args) => {
if (args.length < 2) return original(...args);
//first param can be string or array of strings, need to check and slice before get the middlewares array
View andre.php
<?php
include '../funcoes.php';
include '../conecta.php';
function insert(&$insert_fields)
{
$insert_sql = 'INSERT INTO fases '
.' ('.implode(', ', array_keys($insert_fields)).')'
.' VALUES ('.implode(', ', array_values($insert_fields)).')';
@jpolvora
jpolvora / NotifyPropertyChangedProxy.cs
Created May 19, 2012
NotifyPropertyChangedProxy Generic
View NotifyPropertyChangedProxy.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Reflection;
namespace DynamicUtils
{
public class NotifyPropertyChangedProxy<T> : DynamicObject, INotifyPropertyChanged
@jpolvora
jpolvora / mongo-clear-collections.js
Created Mar 28, 2018
Shell command for Remove all documents for all collections of a MongoDb. Use with caution.
View mongo-clear-collections.js
/* use in a shell like robomongo / robo3t */
db.getCollectionNames().forEach(
function(collection_name) {
db[collection_name].remove({})
}
);
View avoidObstacles.cs
int avoidObstacles(int[] inputArray)
{
var jump = 2;
var max = inputArray.Max() + 1;
while (jump <= max)
{
int multiplier = 1;
bool success = false;
while (true)
{
View arrayMaximalAdjacentDifference.cs
int arrayMaximalAdjacentDifference(int[] inputArray) {
var major = 0;
for (int i = 0; i < inputArray.Length; i++) {
var previous = i - 1;
var next = i + 1;
if (previous < 0 || next > inputArray.Length -1) continue;
var current = inputArray[i];
var preval = inputArray[previous];
View isIpv4Address.cs
bool isIPv4Address(string inputString) {
var split = inputString.Split('.');
if (split.Length != 4) return false;
for (int i = 0; i < 4; i++) {
var str = split[i];
int intVal;
if (!int.TryParse(str, out intVal)) return false;
if (intVal < 0 || intVal > 255) return false;
}
View AlmostIncreasingSequence.cs
bool almostIncreasingSequence(int[] sequence) {
for (int i = 0; i < sequence.Length; i++) {
var items = createArray(i, sequence);
if (isIncreasingSequence(items)) return true;
}
return false;
}
View Couroutine.cs
public static class Coroutine {
public static void BeginExecute(IEnumerable<Promise> enumerable) {
MoveNext(enumerable.GetEnumerator());
}
static void MoveNext(IEnumerator<Promise> enumerator) {
if (enumerator.MoveNext()) {
var promise = enumerator.Current;
promise.Current = promise.Task();
promise.Current._CallBack = () => MoveNext(enumerator);