Skip to content

Instantly share code, notes, and snippets.

View asbjornu's full-sized avatar
💭
He's a loathsome offensive brute, yet I can't look away.

Asbjørn Ulsberg asbjornu

💭
He's a loathsome offensive brute, yet I can't look away.
View GitHub Profile
@asbjornu
asbjornu / GetWholeNumberAndDecimalsFromDecimal.cs
Last active January 26, 2016 12:14
Get whole number and decimals from a System.Decimal in C#
var value = 123.8723498m;
var major = (int)Math.Truncate(value);
var bits = decimal.GetBits(value);
var decimalPart = bits[3];
var bytes = BitConverter.GetBytes(decimalPart);
var decimalLength = bytes[2];
var pow = (int)Math.Pow(10, decimalLength);
var minor = (int)((value - major) * pow);
var formatted = String.Format("{0}.{1}", major, minor);
<?php
/**
* Includes a few useful predicates in the bootstrapped `infiniteScroll` JS object
* that is served along with the rest of the document upon initial page request.
*/
add_filter( 'infinite_scroll_js_settings', 'pla_extra_js_settings' );
function pla_extra_js_settings( $js_settings ) {
$js_settings['text'] = __( "Plus de contenus", "pla" );
@asbjornu
asbjornu / PayEx_CLA.md
Last active September 3, 2018 08:30 — forked from CLAassistant/SAP_CLA
PayEx Individual Contributor License Agreement

PayEx Individual Contributor License Agreement

Thank you for your interest in contributing to open source software projects (“Projects”) made available by PayEx or its affiliates (“PayEx”). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to PayEx in respect of any of the Projects (collectively “Contributions”).

Contrary to “Closed Source” software or proprietary software – where a creator maintains exclusive control over his or her source code – “Open Source Software” is software with source code that anyone can inspect, modify, share, learn from and enhance. Outlined below you will find PayEx Individual Contributor License Agreement under which you as a contributor retain all of your rights, titles and interests in and to your con

@asbjornu
asbjornu / enforce-unicode.py
Last active August 29, 2015 14:14
Enforce UTF-8 Without BOM In All C# Files
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import os
import glob
import fnmatch
import codecs
from chardet.universaldetector import UniversalDetector
# from http://farmdev.com/talks/unicode/

Keybase proof

I hereby claim:

  • I am asbjornu on github.
  • I am asbjornu (https://keybase.io/asbjornu) on keybase.
  • I have a public key whose fingerprint is C671 0035 5226 586F 63DF 0B80 BC58 62FF 43E5 C36E

To claim this, I am signing this object:

@asbjornu
asbjornu / case-insensitive.cs
Last active August 29, 2015 13:57
What would C# look like if it was case insensitive?
namespace CaseInsensitive
{
public class Test
{
private readonly string name;
public Test(string name)
{
this.name = name;
}
@asbjornu
asbjornu / inline-unit-test.cs
Created February 24, 2014 08:39
Unit test syntax for C#
public class HelloWorld
{
public string Say()
{
return "Hello World!";
}
test
{
void Say_ReturnsHelloWorld()
@asbjornu
asbjornu / the_post_thumbnail_url.php
Last active December 18, 2015 09:19
WordPress' missing the_post_thumbnail_url() function.
<?php
/**
* Outputs the URL of the "Featured Image", also known as "Post Thumbnail".
* @param $post_id (optional) The ID of the Post whose Thumbnail you wish to output. When used within "The Loop", this parameter can be ommitted.
* @return void
*/
function the_post_thumbnail_url($post_id = false) {
global $post;
@asbjornu
asbjornu / sum.bas
Created November 29, 2012 15:20
Sums Cell(j, k) in all Tables in a Microsoft Word document and places the Sum in the last Table in the document
'
' Sums Cell(j, k) in all Tables in a Microsoft Word document and places the Sum in the last Table in the document.
'
' It will only work for very specific scenarios where your Tables follow the standard Word Table template where the
' first row and cell contains headers and the last row contains some sort of footer. The rest of the cells in
' the Table will be summarized according to the rowCount, rowOffset, cellCount and cellOffset constants below.
'
Sub Sum()
' This constant is the string of the first cell of the first row in the tables
' it needs to find to add its cells to the total sum
@asbjornu
asbjornu / OpenRastaResourceRegistration.cs
Created August 1, 2012 08:10
OpenRasta resource registration with codecs for three different MIME types and extensions
MediaType json = MediaType.Json.WithQuality(1f);
MediaType xml = MediaType.Xml.WithQuality(0.9f);
MediaType html = MediaType.Html.WithQuality(0.1f);
ResourceSpace.Has
.ResourcesOfType<ResourceBase>()
.WithoutUri
.TranscodedBy<MyXmlCodec>().ForMediaType(xml).ForExtension("xml")
.And.TranscodedBy<MyHtmlCodec>().ForMediaType(html).ForExtension("html")
.And.TranscodedBy<JsonDataContractCodec>().ForMediaType(json).ForExtension("json");