Skip to content

Instantly share code, notes, and snippets.

View bjorn-ali-goransson's full-sized avatar

Björn Ali Göransson bjorn-ali-goransson

View GitHub Profile
@bjorn-ali-goransson
bjorn-ali-goransson / Disassembler.cs
Created February 11, 2020 15:17
Reference implementation from C# in a Nutshell
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
namespace Cloudy.CMS.UI.ContentAppSupport.NameExpressionParserSupport
{
public class Disassembler // http://www.albahari.com/nutshell/cs4ch18.aspx
{
@bjorn-ali-goransson
bjorn-ali-goransson / remove-bom-recursively.ps1
Created August 23, 2019 09:12
Powershell script to remove UTF-8 BOM from files in current directory
# http://robertwesterlund.net/post/2014/12/27/removing-utf8-bom-using-powershell
foreach($file in Get-ChildItem -Path $PSScriptRoot -Include *.php -Recurse -ErrorAction Continue -Force) {
$reader = $file.OpenRead()
$byteBuffer = New-Object System.Byte[] 3
$bytesRead = $reader.Read($byteBuffer, 0, 3)
if ($bytesRead -eq 3 -and
$byteBuffer[0] -eq 239 -and
$byteBuffer[1] -eq 187 -and
$byteBuffer[2] -eq 191)

Keybase proof

I hereby claim:

  • I am bjorn-ali-goransson on github.
  • I am bjornagoransson (https://keybase.io/bjornagoransson) on keybase.
  • I have a public key ASAro2TnvjBS__JKCLOkouQh3UcZAs-qKafn7SGpdQMLgAo

To claim this, I am signing this object:

@bjorn-ali-goransson
bjorn-ali-goransson / test.php
Created March 7, 2018 01:10
List orphaned and missing media (attachments)
<?php
require 'wp-blog-header.php';
if(isset($_GET['delete_post'])){
wp_delete_post($_GET['delete_post']);
die;
}
?>
@bjorn-ali-goransson
bjorn-ali-goransson / adminer-wp.php
Last active August 23, 2019 16:10
Automatic login to Adminer using Wordpress DB credentials (wp-config.php)
<?php
function define_find( $filename = 'wp-config.php' ) { // https://github.com/interconnectit/Search-Replace-DB/blob/master/index.php#L726
if ( $filename == 'wp-config.php' ) {
$filename = dirname( __FILE__ ) . '/' . basename( $filename );
// look up one directory if config file doesn't exist in current directory
if ( ! file_exists( $filename ) )
$filename = dirname( __FILE__ ) . '/../' . basename( $filename );
@bjorn-ali-goransson
bjorn-ali-goransson / Example.csproj
Created July 4, 2017 00:12
Sample csproj for classic .NET apps
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<OutputTypeEx>library</OutputTypeEx>
<BuildOutputTargetFolder>lib\net461</BuildOutputTargetFolder>
</PropertyGroup>
@bjorn-ali-goransson
bjorn-ali-goransson / LoginTest.aspx
Created June 16, 2017 12:14
This file can help by debugging "user cannot log in" problems when in EPiServer the user is just redirected back to the login page when logging in. Probably you are authenticated but not authorized.
<%@ Page Language="C#" %>
<script runat="server">
protected override void OnInit(EventArgs e){
Response.Write(User.Identity.Name);
Response.Write("<br>");
foreach(var role in System.Web.Security.Roles.GetRolesForUser()){
Response.Write(role);
Response.Write("<br>");
}
}
@bjorn-ali-goransson
bjorn-ali-goransson / HttpUtility.cs
Created July 3, 2016 14:24
Standalone HttpUtility for using ParseQueryString without dependency on System.Web
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@bjorn-ali-goransson
bjorn-ali-goransson / AwsAuthenticator.cs
Created May 4, 2016 17:20
Authenticate to AWS with RestSharp (nicked from minio-dotnet / V4Authenticator with minor modifications)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
namespace Rest.Authentication
{
public class AwsAuthenticator : RestSharp.Authenticators.IAuthenticator
{
public string AccessKeyId { get; }
@bjorn-ali-goransson
bjorn-ali-goransson / jquery.hasattr.js
Created November 20, 2015 07:40
jQuery hasAttr function
/* HAS ATTRIBUTE */
$.fn.hasAttr = function(attrName){
var element = this[0];
if(element.hasAttribute){
return element.hasAttribute(attrName);