Skip to content

Instantly share code, notes, and snippets.

@eljojo
eljojo / function.rb
Last active July 20, 2023 06:08
Simple Open AI API Client
# frozen_string_literal: true
module Ai
class Function
# Returns a formatted function payload
def to_payload
{
"name" => name,
"description" => description,
"parameters" => parameters,
@eljojo
eljojo / css_classes.rb
Last active June 18, 2023 23:41
proof of concept on how to have Phlex generate CSS classes
# frozen_string_literal: true
module Views
module CssClasses
extend ActiveSupport::Concern
class CssHelper; end
class_methods do
def css_helper
@eljojo
eljojo / Item URI2.js
Created December 21, 2022 16:54
zotero uri
{
"translatorID":"90ed0f17-6ead-42fe-afb9-d34adb230099",
"translatorType":2,
"label":"Item URI para cucho",
"creator":"jojo",
"target":"html",
"minVersion":"2.0",
"maxVersion":"",
"priority":200,
"inRepository":false,
@eljojo
eljojo / hardware-raspberry-pi.nix
Created January 9, 2022 01:12
nixos raspberry pi
{ config, lib, pkgs, modulesPath, ... }:
{
imports =
[
"${fetchTarball "https://github.com/NixOS/nixos-hardware/archive/2a7063461c3751d83869a2a0a8ebc59e34bec5b2.tar.gz" }/raspberry-pi/4"
];
boot.kernelPackages = pkgs.linuxPackages_rpi4;
boot.kernel.sysctl."vm.swappiness" = 0;
[Unit]
After=docker.service docker.socket
After=ifup@eth0.service
Wants=ifup@eth0.service
[Service]
ExecStart=/usr/bin/docker run \
--rm \
--name=traefik \
@eljojo
eljojo / 0_reuse_code.js
Created July 5, 2017 13:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@eljojo
eljojo / string_each_match.rb
Created September 1, 2013 17:12
String#each_match, kind of like String#scan but returning MatchData instead of the simple match. It takes a block as well!
class String
def each_match(regex)
result = []
position = 0
while match_data = regex.match(self, position) do
result << if block_given? then yield(match_data) else match_data end
position = match_data.end(match_data.size - 1)
end
@eljojo
eljojo / frown.coffee
Created August 21, 2013 10:48
show frown face
show_frown_gif = ->
@result.html $('<img>').attr('src', 'http://mrwgifs.com/wp-content/uploads/2013/07/Zooey-Deschanels-Cute-Sad-Frown.gif')
@eljojo
eljojo / amazon_item.rb
Last active December 19, 2015 15:29
Simple Amazon Product Advertisement api client, using Vacuum and Nokogiri. https://github.com/hakanensari/vacuum
class AmazonItem
attr_accessor :asin, :url, :manufacturer, :category, :title, \
:ean, :item_number, :model, :lowest_price, :image_url, \
:list_price, :offer_price
def initialize(attributes = {})
update_attributes(attributes)
end
def update_attributes(new_attributes)