Skip to content

Instantly share code, notes, and snippets.

# Problem Statement:
#
# You are designing a basic garbage collection algorithm class.
#
# The goal of the class is to output an modified version of the input array containing
# references to live objects, the remainder of objects will later be cleared by a function that
# trims all the values
#
# Implement a function that returns a modified array containing a continous sub array of
# live objects and their indices so that all dead objects can be chopped off by the garbage collector.
@aquaflamingo
aquaflamingo / web2context.zsh
Last active January 12, 2025 18:40
Convert webpages to context files for agents.
#!/bin/zsh
function web2context() {
if [[ $# -eq 0 ]]; then
echo "Usage: web2context <url>"
return 1
fi
url="$1"
temp_dir=$(mktemp -d)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "DataModel")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
@aquaflamingo
aquaflamingo / CustomForm.js
Last active July 17, 2021 17:36
React Custom Form with Hooks Example
import React, { useRef, useState, useEffect } from "react";
const useForm = ({ initialValues, onSubmit }) => {
const [values, setValues] = useState(initialValues || {});
const [errors, setErrors] = useState({});
const [touched, setTouched] = useState({});
const [onSubmitting, setOnSubmitting] = useState(false);
const [onBlur, setOnBlur] = useState(false);
const formRendered = useRef(true);
# post.cr
class Post
YAML.mapping({
name: String,
description: String,
})
end
# factory.cr
module Factory
@aquaflamingo
aquaflamingo / main.go
Created October 25, 2020 17:26 — forked from alyssaq/main.go
GET and POST golang API
/*
* Sample API with GET and POST endpoint.
* POST data is converted to string and saved in internal memory.
* GET endpoint returns all strings in an array.
*/
package main
import (
"encoding/json"
"flag"
# Generate a response array consistent with the requirements of the SPEC.
# @return [Array] a 3-tuple suitable of `[status, headers, body]`
# which is suitable to be returned from the middleware `#call(env)` method.
def finish(&block)
if STATUS_WITH_NO_ENTITY_BODY[status.to_i]
delete_header CONTENT_TYPE
delete_header CONTENT_LENGTH
close
return [@status, @headers, []]
else
@aquaflamingo
aquaflamingo / twbs_rails6.md
Last active December 10, 2020 00:12
Twitter Bootstrap Rails 6

Adding Twitter Bootstrap to Rails 6

See also: https://blog.robsdomain.com/twitter-bootstrap-in-rails-6/

Rails 6 mades large changes to how asset compilation is done. In specific sprockets has been removed for javascript processing and replaced with the common webpack utility. Sprockets remains in usage for CSS processing.

When it comes to asset bundling, the "Rails way" is webpack for JavaScript and Sprockets for everything else. The default setup in a fresh Rail 6 install, similar to what Basecamp uses, still compiles CSS, images, and fonts with Sprockets.

This means, if you're a member of the Basecamp camp, all your webpack JavaScript source files would live in app/javascript and all your Sprockets CSS and images would remain in app/assets. Running rails assets:precompile will first build all the Sprockets assets into the public/assets directory, then will build all the webpack assets into the public/packs directory.