Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / mergeKeepShape-test.ts
Last active March 28, 2016 20:06
Merge values and keep the shape of first object, returns a new object instead of mutating
import { mergeKeepShape } from "./mergeKeepShape";
import Immutable from "seamless-immutable"; // Not required, just ensures test does not mutate inputs
describe("mergeShape", function () {
it("should extend only existing properties", () => {
let newObject = mergeKeepShape(
Immutable({
a : 5,
// b is not here
c : 33,
@Ciantic
Ciantic / tasks.json
Last active October 4, 2016 15:20
Visual Studio Code problem matcher for TSLint and Karma webpack tests on Typescript files with sourcemaps.
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["run"],
"tasks": [
{
"taskName": "start",
"args": [],
"isBuildCommand": true,
@Ciantic
Ciantic / dirname-filename-basename.bat
Created April 1, 2016 15:11
How to get filename, dirname, and basename in bat?
set filepath="C:\some path\having spaces.txt"
for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi"
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"
echo %dirname%
echo %filename%
echo %basename%
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="AspNetCI" value="https://www.myget.org/F/aspnetcirelease/api/v3/index.json" />
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
@Ciantic
Ciantic / ExceptionFilter.cs
Last active December 9, 2020 18:05
Exception Middleware vs Exception Filter both return ObjectResult, ASP.NET Core
using System;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Example
{
public class ApiExceptionFilter : Attribute, IExceptionFilter
{
public void OnException(ExceptionContext context)
{
if (context.Exception is Exception) {
@Ciantic
Ciantic / ModelStateValidationFilter.cs
Created April 21, 2016 06:19
Model state validation filter ASP.NET Core
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Example
{
public class ModelStateValidationFilter : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
@Ciantic
Ciantic / NullValidationFilter.cs
Last active April 21, 2016 18:26
Throw an error if null is passed to action. ASP.NET Core
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Example
{
public class NullValidationFilter : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="aspnetcirelease" value="https://www.myget.org/F/aspnetcirelease/api/v3/index.json" />
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
@Ciantic
Ciantic / RequestUserAttribute.cs
Last active May 5, 2016 16:29
Request user attribute, helper for identity
using System;
using System.Threading.Tasks;
using AspNetApiMonolithSample.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace AspNetApiMonolithSample.Mvc
{
/// <summary>
/// Request user modelbinder from UserManager automatically
@Ciantic
Ciantic / instagram_feed.sh
Created June 4, 2016 17:16
Get instagram feed using bash, without API keys
#!/bin/bash
instagram_user_id=25025320
count=12
csrftoken=$(curl --head -k https://www.instagram.com/ 2>&1 | grep -Po "^Set-Cookie: csrftoken=\K(.*?)(?=;)")
curl "https://www.instagram.com/query/" -H "cookie: csrftoken=$csrftoken;" -H "x-csrftoken: $csrftoken" -H "referer: https://www.instagram.com/" --data "q=ig_user($instagram_user_id)%20%7B%20media.after(0%2C%20$count)%20%7B%0A%20%20count%2C%0A%20%20nodes%20%7B%0A%20%20%20%20caption%2C%0A%20%20%20%20code%2C%0A%20%20%20%20comments%20%7B%0A%20%20%20%20%20%20count%0A%20%20%20%20%7D%2C%0A%20%20%20%20date%2C%0A%20%20%20%20dimensions%20%7B%0A%20%20%20%20%20%20height%2C%0A%20%20%20%20%20%20width%0A%20%20%20%20%7D%2C%0A%20%20%20%20display_src%2C%0A%20%20%20%20id%2C%0A%20%20%20%20is_video%2C%0A%20%20%20%20likes%20%7B%0A%20%20%20%20%20%20count%0A%20%20%20%20%7D%2C%0A%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20id%2C%0A%20%20%20%20%20%20username%2C%0A%20%20%20%20%20%20full_name%2C%0A%20%20%20%20%20%20profile_pic_url%0A%20%20%20%20%7D%2C%0A%20%20%20%20thumbnail_src%2C%