Skip to content

Instantly share code, notes, and snippets.

View binki's full-sized avatar

Nathan Phillip Brink binki

View GitHub Profile
ohnobinki@gibby ~ $ python3
Python 3.3.5 (default, May 19 2015, 14:05:03)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> logger_connection = sqlite3.connect('/home/ohnobinki/log.sql')
>>> logger_connection.exec('CREATE TABLE IF NOT EXISTS submission_log (text TEXT)');
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'sqlite3.Connection' object has no attribute 'exec'
@binki
binki / AsyncDisposal.cs
Last active April 10, 2019 20:04 — forked from thomaslevesque/AsyncDisposal.cs
Async disposal
using System;
using System.Threading.Tasks;
class Program
{
static void Main() => new Program().Run().Wait();
async Task Run()
{
Console.WriteLine("Before Using");
await Async.Using(new Test(), t =>
@binki
binki / ip.py
Last active July 4, 2016 04:44
Example of middleware for heroku forwarding
class ReverseProxy(object):
def process_request(self, request):
unsafe = True
try:
forwarded_for_split = [x.strip() for x in request.META['HTTP_X_FORWARDED_FOR'].split(',')]
# Client connecting to heroku’s stuff is the last listed one.
# http://stackoverflow.com/q/18264304/429091
request.META['REMOTE_ADDR'] = forwarded_for_split.pop()
unsafe = False
except KeyError:
@binki
binki / Program.cs
Created July 23, 2016 15:10
Using struct as a parameter list guard
using System;
namespace ParameterDefaultsGuard
{
// The goal is to make it hard to accidentally call the wrong
// overload when wanting to provide multiple overloads and still
// allow overriding defaults through named parameters. To
// accomplish this, we create an empty struct type. This guards
// against passing in null to various positional parameters and
// that being mistakenly passed as the guard. The only way to
@binki
binki / Program.cs
Created July 25, 2016 18:39
MEF only supports generic type closure using nongeneric type as generic type parameters
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
namespace MefGenericExportImports
{
[Export]
public class Program
{
[Import]
@binki
binki / Program.cs
Created July 28, 2016 13:47
Fun with C# expressions and maybe a way to SQL?
using System;
using System.Linq;
using System.Linq.Expressions;
namespace ExpressionsFun
{
static class Program
{
static void Main(string[] args)
{
@binki
binki / Program.cs
Created July 29, 2016 15:03
C# static initializers don’t care about inheritance
// Apparently, accessing a static member of a subclass does not initialize
// the static members of the base class unless you explicitly cause this to
// happen.
using System;
namespace StaticInitializationInheritance
{
class Program
{
/* -*- c-file-style: "linux" -*- */
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, const char *const argv[])
{
struct stat statbuf;
if (argc < 2)
@binki
binki / github-fluid-moz-stylish.css
Last active August 15, 2016 15:16
Fix GitHub requiring horitontal scrolling/not being fluid
@namespace url(http://www.w3.org/1999/xhtml);
/*
* With this style, github README pages become fluid and no longer
* require horizontal scrolling to read: http://imgur.com/pyruCm0
*
* Without, lots of annoying horizontal scrolling: http://imgur.com/wofNtra
*/
@-moz-document domain("github.com") {

Mercurial supports nested quoting contexts:

ohnobinki@gibby ~/dcx-ridik-variable-substitution $ t="{'a{'b{pad('x', 2, ',', True)}'}'}"; echo "${t}"; hg log -l1 --template "${t}"; echo
{'a{'b{pad('x', 2, ',', True)}'}'}
ab,x

It also supports “weirdly quoted strings”, as I call them: