Skip to content

Instantly share code, notes, and snippets.

View abjurato's full-sized avatar
💜

Anatoly Rosencrantz abjurato

💜
View GitHub Profile
@abjurato
abjurato / macho_extractor.c
Created September 27, 2019 12:54 — forked from C0deH4cker/macho_extractor.c
Program that will extract a segment from a mach-o file. Should even work on Linux/BSD/UNIX?
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
/* For supporting Linux and other systems that don't have mach-o headers */
@abjurato
abjurato / Logger.swift
Created May 4, 2016 18:37
Logger for Heroku. Swift, Perfect, mustache and PostgreSQL on Heroku.
#if os(Linux)
import Glibc
#else
import Darwin
#endif
enum Logger {
static func info(string: String) {
fputs(string, stdout)
fflush(stdout)
@abjurato
abjurato / makefile
Created May 2, 2016 19:56
makefile for CatFoodServer deployment to Heroku. Swift, Perfect, mustache and PostgreSQL on Heroku.
# Makefile for CatFoodServer
TARGET = CatFoodServer
OS = $(shell uname)
SWIFT_FILES = $(TARGET)/PerfectHandlers.swift \
$(TARGET)/CatNameHandler.swift \
$(TARGET)/FoodListHandler.swift
MUSTACHE_ROOT = $(TARGET)/Mustache
@abjurato
abjurato / CatNameHandler.swift
Created May 2, 2016 07:01
CatNameHandler for processing CatName mustache template. Swift, Perfect, mustache and PostgreSQL on Heroku.
import PerfectLib
class CatNameHandler: PageHandler {
func valuesForResponse(context: MustacheEvaluationContext, collector: MustacheEvaluationOutputCollector) throws -> MustacheEvaluationContext.MapType {
let dict:MustacheEvaluationContext.MapType = ["name": "Sasha"]
return dict
}
}
@abjurato
abjurato / PerfectHandlers.swift
Created May 2, 2016 06:58
Required global function to make Perfect work. Swift, Perfect, mustache and PostgreSQL on Heroku.
import PerfectLib
// This function is required. The Perfect framework expects to find this function
// to do initialization
public func PerfectServerModuleInit() {
PageHandlerRegistry.addPageHandler("CatName") {
// This closure is called in order to create the handler object.
// It is called once for each relevant request.
// The supplied WebResponse object can be used to tailor the return value.
@abjurato
abjurato / PerfectHandlers.swift
Created May 2, 2016 06:52
Junk to add to PerfectHandlers.swift to register FoodList mustache template. Swift, Perfect, mustache and PostgreSQL on Heroku.
PageHandlerRegistry.addPageHandler("FullFoodList") {
(r:WebResponse) -> PageHandler in
return FoodListHandler()
}
@abjurato
abjurato / FoodListHandler.swift
Created May 2, 2016 06:49
FoodListHandler class for processing FoodList mustache template. Swift, Perfect, mustache and PostgreSQL on Heroku.
import PerfectLib
import PostgreSQL
class FoodListHandler: PageHandler {
let dbHost = "localhost"
let dbName = "cat_food"
let dbUsername = //PUT YOUR SYSTEM USERNAME HERE!
let dbPassword = ""
func valuesForResponse(context: MustacheEvaluationContext, collector: MustacheEvaluationOutputCollector) throws -> MustacheEvaluationContext.MapType {