Skip to content

Instantly share code, notes, and snippets.

@tarnacious
tarnacious / build-qcow2.nix
Last active February 22, 2024 01:22
Build a bare bones bootable nixos qcow2 image suitable for running with libvirt/qemu/kvm.
{ config, lib, pkgs, ... }:
with lib;
{
imports =
[
<nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
./machine-config.nix
];
@tarnacious
tarnacious / helpers.cs
Created December 20, 2011 00:20
Quick hack to validate a facebook javascript api auth cookie on the server.
public bool Authenticate()
{
var FacebookAppId = ConfigurationManager.AppSettings["FACEBOOK_APPID"];
var FacebookAppSecret = ConfigurationManager.AppSettings["FACEBOOK_SECRET"];
var cookie = Request.Cookies["fbs_" + FacebookAppId];
if (cookie == null) return false;
@tarnacious
tarnacious / configuration.nix
Last active September 25, 2023 11:24
Building NixOS qcow2 images with flakes
{ config, lib, pkgs, ... }: {
boot.kernelPackages = pkgs.linuxPackages_5_15;
users.users = {
tarn = {
isNormalUser = true;
extraGroups = [ "wheel" ];
password = "";
};
};
@tarnacious
tarnacious / search.cs
Created November 28, 2011 06:47
Searching for multiple terms using the Umbraco Examine API.
// This seems way too difficult for what you would expect to be a pretty common task;
// taking a search string from the user and finding documents which contain some or all of the terms
// in the search string.
// This function naively splits a search string into terms and finds documents
// which contain some or all of the terms. Does not handle quoted terms as or ignore case as it should.
public IEnumerable<SearchResult> Search(string searchString, string[] fields)
{
// Spit the search string and return an empty list if no search string was provided.
if (string.IsNullOrEmpty(searchString)) return new List<SearchResult>();
@tarnacious
tarnacious / app.coffee
Created June 13, 2011 09:50
Asteroids
HEIGHT = 600
WIDTH = 900
class Vector
constructor:(@x,@y) ->
add: (other) ->
new Vector @x + other.x, @y + other.y
@tarnacious
tarnacious / gist:874052
Created March 17, 2011 09:26
Compiling SelectMany Linq without System.Linq. Also a List Monad.
using System;
using System.Collections.Generic;
public static class ExtensionMethods
{
public static IEnumerable<T> ToList<T>(this T value) {
yield return value;
}
public static IEnumerable<U> SelectMany<T, U>(this IEnumerable<T> m, Func<T, IEnumerable<U>> k)
FROM node:latest
WORKDIR /app
COPY . .
RUN yarn
CMD ["node", "index.js"]
@tarnacious
tarnacious / check.py
Last active June 9, 2021 07:58
Check for a desturbance in the CORS
import requests
from datetime import datetime
def check(domain, referer):
url = 'https://' + domain + '/mesh/v1/category?location=com'
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Access-Control-Request-Method': 'GET',
@tarnacious
tarnacious / comments.py
Created January 29, 2020 09:57
scan comments in pyyaml
import yaml
from yaml.composer import Composer
from yaml.reader import Reader
from yaml.scanner import Scanner
from yaml.parser import Parser
from yaml.constructor import SafeConstructor
from yaml.resolver import Resolver
class CommentsScanner(Scanner):
def scan_to_next_token(self):
@tarnacious
tarnacious / main.py
Created January 29, 2020 08:46
maintain key order in pyyaml for python 2.7+
import yaml
from collections import OrderedDict
class OrderedDumper(yaml.SafeDumper):
pass
def _dict_representer(dumper, data):
return dumper.represent_mapping(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
data.items())