Skip to content

Instantly share code, notes, and snippets.

View tomthorogood's full-sized avatar
🎸

Tom Thorogood tomthorogood

🎸
View GitHub Profile
@tomthorogood
tomthorogood / app.py
Created April 5, 2021 15:06
VCards in python+flask
# Simplistic example using send_file to send the contents generated in the service
@app.route("/vcard/<href_token>")
def get_person_vcard(request: requests.HTTPRequest, href_token: str):
vcard_stream = self.vcard_service.get_vcard(b64decode(href_token.encode('UTF-8')).decode('UTF-8'))
return send_file(vcard_stream, mimetype='text/vcard')
int do_work(int* c) {
int i*; // This is never defined, and its value cannot be guaranteed.
int j = 42; // This is never used, but the programmer likely intended for it to be.
return c + *i; // Because i is never defined, this will likely be incorrect.
}
def reverse(string):
return string[::-1]
def concat(*strings):
return "".join(strings)
def create_factory(obj, *args, **kwargs):
def factory(*oargs, **okwargs):
@tomthorogood
tomthorogood / utf8.cpp
Last active December 16, 2015 00:29
Playing with unicode chars for data packing purposes:
#include <iostream>
#include <cstring>
using namespace std;
int main() {
const char* foo = "✓";
const char* foo2 = "\xe2\x9c\x93";
const char* bar = "é";
const char* baz = "a";
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#define PACKING_DELIMITER 999999
void tokenize(const char* input)
{
@tomthorogood
tomthorogood / gist:5310782
Created April 4, 2013 14:26
Way better way of finding ints in strings
int main() {
std::string foostring = "this is a test [[6379]] of the number finding system.";
auto digstart = foostring.find_first_of("1234567890");
auto tail = foostring.substr(digstart);
auto digend = tail.find_first_not_of("1234567890");
auto digit = tail.substr(0,digend);
auto digint = atoi(digit.c_str());
std::cout << digint << std::endl;
return 0;
}
@tomthorogood
tomthorogood / mcmd_to_int.c
Last active December 15, 2015 15:49
Concept for handling Mogu command tokens by converting them to ints early if possible. Implemented in pure C for efficiency, but it's probably really terrible code.
// Store as a const char* to avoid having to convert back and forth while
// we suss out which tokens are integers.
const char* inputString = redisRepy->str;
int len = strlen(inputString);
int strIndex = 0;
@tomthorogood
tomthorogood / mogu_int_to_script.py
Last active December 15, 2015 06:09
A snippet from Mogu's MoguString(MultiString) class, which translates from Mogu's integral syntax to human-readable syntax
def integral_to_script(self, original_integral):
"""
Converts integral commands to human-readable MoguScript.
For instance, "2 58 foo 6 26 58 bar 6" would be translated to:
'set widget foo content to widget bar content'
However, there can be contextual
differences which may need to be set up, because some integral
representations have multiple textual representations i
(content|contents|text, for instance).
@tomthorogood
tomthorogood / euler.py
Last active December 14, 2015 14:58
An implementation of the Euler method for approximating function returns
# Tom A. Thorogood - 2013 - github.com/tomthorogood
#
# This software is free to use, modify, and distribute as you wish. It is intended for educational purposes only, and is
# provided without a guarantee of functionality or warranty of any sort. Usage is solely at your own risk.
#
# The Euler provides a method to estimate the value of a function (f) given an input value (x).
#
# The class requires the following:
# 1) An equation with two variables (x and y)
# 2) A known x, and known y value
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main() {
string var1 = "butt";
string var2 = "soap";