Skip to content

Instantly share code, notes, and snippets.

View Cosmo's full-sized avatar
📎
It looks like you're looking at my profile. Would you like help?

Devran Cosmo Uenal Cosmo

📎
It looks like you're looking at my profile. Would you like help?
View GitHub Profile
@xiaohui-zhangxh
xiaohui-zhangxh / application_controller.rb
Last active January 6, 2024 11:20
Make active_model_serializers render Pagy result as jsonapi response, with pagination meta and links
class Api::ApplicationController < ActionController::API
include Pagy::Backend
include PagyCollectionSerializer::ControllerMixin
end
@lingceng
lingceng / plain_chatgpt_client.rb
Created May 29, 2023 00:34
Ruby chatgpt chat api when stream mode, deal with error handle and chunk break.
class Chatgpt::PlainChatgptClient
def self.chat(parameters)
@client ||= generate_client
res = @client.post("/v1/chat/completions") do |req|
if parameters[:stream].is_a?(Proc)
req.options.on_data = to_json_stream(user_proc: parameters[:stream])
parameters[:stream] = true
end
@Reiss-Cashmore
Reiss-Cashmore / disable.sh
Created February 19, 2023 22:35
disable.sh
#!/bin/zsh
#Credit: Original idea and script disable.sh by pwnsdx https://gist.github.com/pwnsdx/d87b034c4c0210b988040ad2f85a68d3
#*****Work in progress*****
#Disabling unwanted services on macOS 11 Big Sur
#Modifications written in /private/var/db/com.apple.xpc.launchd/ disabled.plist, disabled.501.plist & disabled.205.plist
#Disabling SIP might not be required, still testing.
sudo mkdir mnt
sudo mount -o nobrowse -t apfs /dev/disk1s5 mnt/
@equivalent
equivalent / README.md
Last active September 29, 2024 08:09
Rails 7 importmaps dropzone.js direct upload ActiveStorage

This is simple implementation of technologies in hobby project of mine built in Rails7 where I need direct upload to S3.

@memoryleak
memoryleak / create-monterey-iso.sh
Last active May 1, 2024 12:38
Create a Mac OS Monterey ISO file from the official installation DMG file
#!/usr/bin/env bash
sudo hdiutil create -o /tmp/Monterey -size 16g -volname Monterey -layout SPUD -fs HFS+J
sudo hdiutil attach /tmp/Monterey.dmg -noverify -mountpoint /Volumes/Monterey
sudo /Applications/Install\ macOS\ Monterey.app/Contents/Resources/createinstallmedia --volume /Volumes/Monterey --nointeraction
hdiutil eject -force /Volumes/Install\ macOS\ Monterey
hdiutil convert /tmp/Monterey.dmg -format UDTO -o ~/Downloads/Monterey
mv -v ~/Downloads/Monterey.cdr ~/Downloads/Monterey.iso
sudo rm -fv /tmp/Monterey.dmg
@hopsoft
hopsoft / Dockerfile
Last active May 17, 2023 19:58
Dockerize your Rails app
FROM ruby:3.0-alpine
RUN apk add --no-cache --update \
ack \
bash \
build-base \
curl \
git \
htop \
less \
@iccir
iccir / SimStatusBar.sh
Last active October 22, 2024 07:17
iOS Simulator Status Bars
# iPhone with home button
xcrun simctl status_bar booted clear
xcrun simctl status_bar booted override \
--time "9:41 AM" \
--wifiBars 3 --cellularBars 4 --operatorName ""
xcrun simctl spawn booted defaults write com.apple.springboard SBShowBatteryPercentage 1
# iPhone X
xcrun simctl status_bar booted clear
xcrun simctl status_bar booted override --time "9:41" --wifiBars 3 --cellularBars 4
@ole
ole / !swiftui-reflection-dump.md
Last active June 24, 2024 18:00
A dump of the SwiftUI.framework binary for the iOS simulator (as of Xcode 12.0 beta 2) using the swift-reflection-dump tool.

A dump of the SwiftUI.framework binary for the iOS simulator (as of Xcode 12.0 beta 2) using the swift-reflection-dump tool.

Note: I used a Swift 5.3 compiler build from a few weeks ago that I had laying around. Because of ABI stability, I don't think the swift-reflection-dump version has to match the compiler version that was used to build the binary, but I'm not 100% sure.

@mfts
mfts / letsencrypt.sh
Created January 29, 2020 18:19
Create Letsencrypt wildcard certificate
brew install certbot
# change <my.domain> to preferred domain
certbot certonly --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-public-ip-logging-ok -d '*.<my.domain>' -d <my.domain>
# add certificates to heroku
heroku certs:add -a eduqai-prod /etc/letsencrypt/live/<my.domain>/fullchain.pem /etc/letsencrypt/live/<my.domain>/privkey.pem
# may need to run with sudo
@artyom-stv
artyom-stv / gist:a87f572999074aa9afab03d8e96eef2e
Last active August 2, 2024 18:21
Visitor-based approach for accessing `@ViewBuilder`-provided content
// SwiftUI public API
public protocol View {
associatedtype Body: View
var body: Self.Body { get }
}
extension Never: View {
public typealias Body = Never