Skip to content

Instantly share code, notes, and snippets.

View harlanji's full-sized avatar

Harlan J. Iverson harlanji

View GitHub Profile
@harlanji
harlanji / dataclass_as_dict_transcoding.py
Last active April 12, 2023 03:28
Python EventSourcing: DataClassAsDict Transcoding
import weakref
from eventsourcing.application import Application
from eventsourcing.persistence import Transcoding, Transcoder
from dataclasses import asdict
from dacite import from_dict
class DataClassAsDict (Transcoding):
"""
@harlanji
harlanji / patreon_client.py
Last active March 31, 2023 17:49
Fetching content from Patreon API in Python
import os
import patreon
import requests
from dotenv import load_dotenv
load_dotenv()
access_token = os.environ.get('PATREON_ACCESS_TOKEN')
<?php
$db = new PDO('sqlite::memory:');
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$db->setAttribute( PDO::ATTR_CASE, PDO::CASE_LOWER );
$db->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC );
$db->exec("CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, username TEXT NOT NULL)") . "\n";
@harlanji
harlanji / dict-password.sh
Created September 28, 2014 02:53
dict-password.sh - Generate words on the CLI like XKCD #936
#!/bin/sh
# dict-password.sh
# Harlan Iverson <h.iverson@gmail.com>
# Generate words on the CLI like XKCD #936 -- http://xkcd.com/936/
# usage: DICT=/usr/share/dict/words COUNT=4 ASK=y ./dict-password.sh > newpass
# or simply: ./dict-password.sh
@harlanji
harlanji / Demo.java
Created August 29, 2011 23:42
Best way to add custom converters to spring-data-mongodb?
MongoTemplate mongo = ...;
List<Converter> converters = new ArrayList<Converter>();
converters.add(new Converter<DBObject, Participant>() {
public Participant convert(DBObject s) {
throw new UnsupportedOperationException("Not supported yet 1.");
}
});
converters.add(new Converter<Participant, DBObject>() {
@harlanji
harlanji / index.js
Created August 23, 2011 07:41
Creating a unique index on a nested array of objects.
// http://www.mongodb.org/display/DOCS/Multikeys
// Embedded object fields in an array
db.testnest.insert({"title" : "How the west was won",
"comments" : [{"text" : "great!" , "author" : "sam"},
{"text" : "ok" , "author" : "julie"}],
"_id" : ObjectId("497ce79f1ca9ca6d3efca325")});
// Tried both of these indexes
//db.testnest.ensureIndex({'comments.author': 1}, {unique: true});
@harlanji
harlanji / javap-out.txt
Created January 14, 2011 20:02
Best practice for extensible SBT plugins?
harlan@plato:/tmp/scalamixin$ javap MyProject
Compiled from "mixin.scala"
public class MyProject extends BasicProject implements QUnitSupport,scala.ScalaObject{
public scala.collection.immutable.List qunitSources();
public void QUnitSupport$_setter_$qunitSources_$eq(scala.collection.immutable.List);
public void qunitRun();
public scala.collection.immutable.List jsSources();
public void JavascriptSupport$_setter_$jsSources_$eq(scala.collection.immutable.List);
public MyProject(ProjectInfo);
}
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 1. -->
<groupId>com.example</groupId>
<artifactId>my-library</artifactId>
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<script src="scripts/require.js"></script>
<!-- This require() call will load project.js -->
<script>require(["project"]);</script>
</head>
<body>
<h1>My Sample Project</h1>