Skip to content

Instantly share code, notes, and snippets.

View jpolvora's full-sized avatar

Jone jpolvora

View GitHub Profile
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace AsyncKonsole
{
class Program
{
<!-- 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 />
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
@jpolvora
jpolvora / andre.php
Last active September 7, 2018 07:26
<?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 11:31
NotifyPropertyChangedProxy Generic
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 March 28, 2018 05:24
Shell command for Remove all documents for all collections of a MongoDb. Use with caution.
/* use in a shell like robomongo / robo3t */
db.getCollectionNames().forEach(
function(collection_name) {
db[collection_name].remove({})
}
);
int avoidObstacles(int[] inputArray)
{
var jump = 2;
var max = inputArray.Max() + 1;
while (jump <= max)
{
int multiplier = 1;
bool success = false;
while (true)
{
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];
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;
}
bool almostIncreasingSequence(int[] sequence) {
for (int i = 0; i < sequence.Length; i++) {
var items = createArray(i, sequence);
if (isIncreasingSequence(items)) return true;
}
return false;
}