Skip to content

Instantly share code, notes, and snippets.

@icyleaf
icyleaf / ar_migrate.rb
Last active May 5, 2024 14:55
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@delneg
delneg / f.html
Created April 12, 2017 18:00
Django 'active' for navbar
# In this example I make difference for 3 urls, this can be messy if you have an URL that is like /posts/whatever/contacts because there is 2 places that will return True (2nd and 3rd li)
# So here is the better option for handling this:
{% with request.resolver_match.url_name as url_name %}
<ul id="menu">
<li class="{% if url_name == 'home' %}active{% endif %}">Home</li>
<li class="{% if url_name == 'blog' %}active{% endif %}">Posts</li>
<li class="{% if url_name == 'contact' %}active{% endif %}">Contact</li>
</ul>
@dhh
dhh / linux-setup.sh
Last active May 5, 2024 14:54
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
@zargony
zargony / ipv6proxy
Last active May 5, 2024 14:52
Automatic SSH jump host for IPv6-only hosts
#!/bin/sh
# Automatic SSH jump host for IPv6-only hosts.
# Usage in ~/.ssh/config: ProxyCommand ~/.ssh/ipv6proxy <jumphost> %h %p
# If a host is reachable via IPv6, a direct connection is made.
# Otherwise a jump host is used (which shall support IPv6).
if ping6 -c1 $2 >/dev/null 2>&1; then
exec nc -6 $2 $3
else
exec ssh -q $1 "nc -6 $2 $3"
@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active May 5, 2024 14:52
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@joe-scotto
joe-scotto / Animation
Last active May 5, 2024 14:50
QMK OLED Displays
#ifdef OLED_ENABLE
// Rotate OLED
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_90;
}
// Animation parameters
#define FRAME_DURATION 333 // How long each frame lasts in milliseconds
@davidfoster
davidfoster / KalmanFilterFloat.cs
Last active May 5, 2024 14:49
Simple Kalman filtering in Unity.
using System.Collections.Generic;
/// <summary>A Kalman filter implementation for <c>float</c> values.</summary>
public class KalmanFilterFloat {
//-----------------------------------------------------------------------------------------
// Constants:
//-----------------------------------------------------------------------------------------
public const float DEFAULT_Q = 0.000001f;
@Klerith
Klerith / instalaciones.md
Last active May 5, 2024 14:45
Instalaciones recomendadas - Curso de Angular de cero a experto
@eduardozulian
eduardozulian / wp-taxonomy-dropdown.php
Last active May 5, 2024 14:45
Callback function for 'meta_box_cb' argument inside register_taxonomy() that replaces the regular checkboxes with a plain dropdown list
<?php
/**
* Callback function for taxonomy meta boxes
*
* A simple callback function for 'meta_box_cb' argument
* inside register_taxonomy() that replaces the regular
* checkboxes with a plain dropdown list
*
* @param [type] $post [description]
* @param [type] $box [description]