Skip to content

Instantly share code, notes, and snippets.

View vpetkovic's full-sized avatar
👾

Vojislav Petkovic vpetkovic

👾
View GitHub Profile
@vpetkovic
vpetkovic / UserInput.php
Created November 16, 2018 01:52 — forked from chtombleson/UserInput.php
Helper Class for sanitizing user input in PHP
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Christopher Tombleson <chris@cribznetwok.com>
*
* 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
@vpetkovic
vpetkovic / genNewPw.cs
Created September 24, 2019 13:05
Helper classes
public void GenerateNewPassword(PasswordOptions opts = null)
{
#region Generating New Password
if (opts == null) opts = new PasswordOptions()
{
RequiredLength = 12,
RequiredUniqueChars = 4,
RequireDigit = true,
RequireLowercase = true,
RequireNonAlphanumeric = true,
@vpetkovic
vpetkovic / apiHttpResponses
Last active September 26, 2019 13:32
The following table lists all the methods of ApiController class that returns an object of a class that implements IHttpActionResult interface.
- **BadRequest()**: Creates a BadRequestResult object with status code 400.
- **Conflict()**: Creates a ConflictResult object with status code 409.
- **Content()**: Creates a NegotiatedContentResult with the specified status code and data.
- **Created()**: Creates a CreatedNegotiatedContentResult with status code 201 Created.
- **CreatedAtRoute()**: Creates a CreatedAtRouteNegotiatedContentResult with status code 201 created.
- **InternalServerError()**: Creates an InternalServerErrorResult with status code 500 Internal server error.
- **NotFound()**: Creates a NotFoundResult with status code404.
- **Ok()**: Creates an OkResult with status code 200.
- **Redirect()**: Creates a RedirectResult with status code 302.
- **RedirectToRoute()**: Creates a RedirectToRouteResult with status code 302.
@vpetkovic
vpetkovic / mimeController.cs
Last active September 26, 2019 15:50
To guess MIME type based on byte[]: https://github.com/hey-red/Mime
public class ValuesController : Controller
{
private readonly IMimeMappingService _mimeMappingService;
public ValuesController(IMimeMappingService mimeMappingService)
{
_mimeMappingService = mimeMappingService;
}
[HttpGet]
@vpetkovic
vpetkovic / callWebAPI.cs
Created October 1, 2019 14:17
using RestSharp using HTTPClient using WebClient
using RestSharp;
using System.Net;
using System.Net.Http;
public static void useRestSharp(string url)
{
var client = new RestClient(url);
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
<?php
class config
{
private static $instance;
public function __construct()
{
self::$instance = $this->dbConnect();
}
// Install System.Data.DataSetExtensions from NUGET
using System;
using System.Linq;
using System.Data;
public class newClass
{
public object DataTableToObject()
{
SELECT
name,
base_object_name,
type
FROM
sys.synonyms
ORDER BY
name;
@vpetkovic
vpetkovic / recurrDates.sql
Last active November 13, 2019 01:38
ROWS UNBOUNDED PRECEDING is the abbreviated version of ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. This window frame-ing option means that for each row the SUM will include itself and all predecessors as ordered by id. The ROWS option is pote
CREATE FUNCTION dbo.fn_recurringDates(
@wkDayPattern tinyint=127, --- 1=Mon, 2=Tue, 4=Wed, ... 127=All
@dayFrequency tinyint=1, --- 1=All, 2=every second, ...
@exactDay tinyint=NULL, --- Specific day number of the month
@occurrenceNo tinyint=NULL, -- 1=First, 2=Second, ... 0=Last
@occurrenceType tinyint=NULL, -- ... of 1=Week, 2=Month, 3=Year
@weekFrequency tinyint=1, --- 1=Every week, 2=Every second, etc
@exactWeek tinyint=NULL, -- Specific ISO week of the year
// Install System.Data.DataSetExtensions from NUGET
using System;
using System.Linq;
using System.Data;
public class newClass
{
public object DataSetToObject()
{