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 / 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)
@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 / 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 / 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 / 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 );

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 / 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);
@bjorn-ali-goransson
bjorn-ali-goransson / index.html
Last active July 5, 2018 07:13
Minimal Bootstrap+jQuery+BootstrapJS+FontAwesome template
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head><body>
<div class="container"><span class="btn btn-success"><i class="fa fa-coffee"></i></span></div>
</body></html>
@bjorn-ali-goransson
bjorn-ali-goransson / Gist.java
Created April 24, 2014 21:00
One line Toast creation in Android
Toast.makeText(getApplicationContext(), "Hello toast!!", Toast.LENGTH_LONG).show()
@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;
}
?>