Skip to content

Instantly share code, notes, and snippets.

View Sleepful's full-sized avatar
🐢
boo 👻

Jose Vargas Sleepful

🐢
boo 👻
View GitHub Profile

How to pick between Zig and Rust.

flowchart TD
    A(Do you want to `malloc`?) -->| yes |Zig
    A(Do you want to `malloc`?) -->| No |Rust
@Sleepful
Sleepful / tmux.sh
Last active July 2, 2023 05:47
FZF to select tmux windows and move them to another session. You may select multiple windows.
# this in your tmux config
bind M run-shell "source ~/.tmux/functions.sh && move_windows"
# this inside ~/.tmux/functions.sh
#!/bin/bash
#
function move_windows() {
windows=$(
{
"title": "swap numbers and shift+numbers",
"rules": [
{
"description": "swap numbers and shift+numbers",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "1",
@Sleepful
Sleepful / fhead.ex
Last active November 18, 2022 22:32
defmodule Fheads do
defp set_required(set, :built, :new), do: set
defp set_required(set, :built, :submit) do
type = get_field(set, :type)
assoc = get_field(set, type)
put_assoc(set, type, required: assoc.required)
end
# Re-usable outside of a changeset! :D
@Sleepful
Sleepful / case.ex
Last active November 18, 2022 21:45
defmodule CaseCondIf do
defp set_required(set) do
if !set.valid? do
set
else
state = get_field(set, :__meta__).state
IO.inspect(state)
stage = set.stage
# set_required(set, state, stage)
case {stage, state} do
defmodule WordBase.Classifier.Value do
@kinds [
%{string: "filter", atom: :Filter},
%{string: "word", atom: :Word}
]
@types [
%{string: "bool", atom: :Bool, db_type: :boolean},
%{string: "text", atom: :Text, db_type: :string},
%{string: "datetime", atom: :Datetime, db_type: :naive_datetime}
]
# the join tables, many_to_many between:
#
# - categories_type(s)
# - filter
#
# - categories_type(s)
# - word
#
# type(s) refer to: bool, text, multi, datetime
#
var nsp2 = io.of('/2');
nsp2.on('connection', socket => {
socket.on('change color', (color) => {
nsp2.broadcast.emit('change color', color)
}
var nsp3 = io.of('/3');
nsp3.on('connection', socket => {
socket.on('change color', (color) => {
nsp3.broadcast.emit('change color', color)
@Sleepful
Sleepful / mkefile
Last active September 6, 2018 05:25
# change application name here (executable output name)
TARGET=knapsack
# compiler
CC=gcc
# debug
DEBUG=-g
# optimisation
OPT=-O0
# warnings
#!/bin/bash
# Bash Menu Script Example
add_to_log() {
command echo $1>>log
}
crear(){
echo "Nombre Usuario"
read namevar
echo "- Su respuesta: $namevar"