Skip to content

Instantly share code, notes, and snippets.

int64_t ipow(int64_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 255, // anything past 63 is a guaranteed overflow with base > 1
@hmans
hmans / application.html.slim
Last active October 27, 2023 17:52
Application layout for Rails (4 and 5), Slim style.
doctype html
html
head
title My App
meta name="viewport" content="width=device-width, initial-scale=1.0"
= stylesheet_link_tag "application", media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag "application", 'data-turbolinks-track' => true
= csrf_meta_tags
body
@firstclown
firstclown / fish_prompt.fish
Created December 5, 2013 00:53
My current fish prompt. Shows the current directory, who's logged in, current host (last two helpful for SSH sessions) and then a git status prompt displaying current branch and the branches status. Finally the actual prompt is on the next line, to keep lots of space for commands.
set -g __fish_git_prompt_show_informative_status 1
set -g __fish_git_prompt_hide_untrackedfiles 1
set -g __fish_git_prompt_color_branch magenta bold
set -g __fish_git_prompt_showupstream "informative"
set -g __fish_git_prompt_char_upstream_ahead "↑"
set -g __fish_git_prompt_char_upstream_behind "↓"
set -g __fish_git_prompt_char_upstream_prefix ""
set -g __fish_git_prompt_char_stagedstate "●"

Install cask that extends the brew command :

brew install phinze/cask/brew-cask

Install calibre using cask :

brew cask install calibre
@mgamini
mgamini / Elixir Email Validation
Last active March 27, 2023 17:42
Elixir Email Validation
defmodule EmailValidator do
# ensure that the email looks valid
def validate_email(email) when is_binary(email) do
case Regex.run(~r/^[\w.!#$%&’*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i, email) do
nil ->
{:error, "Invalid email"}
[email] ->
try do
Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email
@ybakos
ybakos / Random.jack
Created November 3, 2014 20:12
Jack Pseudo Random Numbers for Nand 2 Tetris
/* Random.jack
* By Mark Armbrust
* http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Random-number-generator-for-hack-cpu-td4025503.html
* Also see:
* http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Pseudo-Random-Number-Generator-td4026059.html#a4027617
*/
class Random {
static int seed;
@cjddmut
cjddmut / EasingFunctions.cs
Last active May 5, 2024 09:12
Easing Functions for Unity3D
/*
* Created by C.J. Kimberlin
*
* The MIT License (MIT)
*
* Copyright (c) 2019
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@franc
franc / window.ex
Created September 3, 2015 15:55
elixir attempt at getting WX to draw a line
defmodule AudioRenderer.Window do
@moduledoc """
A window to draw our audio renderer within.
"""
@title 'Audio Renderer'
require Record
Record.defrecordp :wx, Record.extract(:wx, from_lib: "wx/include/wx.hrl")
Record.defrecordp :wxClose, Record.extract(:wxClose, from_lib: "wx/include/wx.hrl")
@tanyuan
tanyuan / smart-caps-lock.md
Last active May 8, 2024 16:05
Smart Caps Lock: Remap Caps Lock to Control AND Escape

Smart Caps Lock: Remap to Control AND Escape (Linux, Mac, Windows)

Caps Lock 變成智慧的 Control 以及 Escape

  • 單獨輕按一下就是 Escape
  • 若按下時同時按著其他鍵,就會是 Control

這應該是 Vim 和 Emacs 的最佳解了!(Emacs? Bash 的快捷鍵就是 Emacs 系列的)

  • Send Escape if you tap Caps Lock alone.
@riverrun
riverrun / workout_form.ex
Created August 2, 2016 09:00
Json / map in Phoenix form
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :type, class: "control-label" %>
<%= select f, :type, @workout_types, prompt: "Choose workout type", class: "form-control" %>