Skip to content

Instantly share code, notes, and snippets.

View inoas's full-sized avatar
🏠
Working from home

inoas

🏠
Working from home
View GitHub Profile

Variables

const shade = 100;
type Shade = 100;

Functions

@tfwright
tfwright / deploy.yml
Last active May 12, 2023 09:18
Ansible Phoenix deployment playbook
---
# ansible 2.9.0
- name: Deploy to production
hosts: production
remote_user: user
vars:
app_root: /home/user/apps/my_app
tasks:
def join_game(user_id, game_id) do
with {:ok, user} <- Users.get(user_id),
{:ok, game} <- Games.get(game_id),
false <- Game.is_full?(game),
false <- Game.is_started?(game),
true <- User.has_permission?(user, game)
do
Game.add_user(game, user)
else
# Don't care what specific thing failed
@nathanl
nathanl / postgresql_serializable_isolation.sql
Last active July 15, 2022 14:11
PostgreSQL Serializable Isolation - false positives
-- (This code was run in PostgreSQL 9.6.1)
-- Demonstration of how serializable isolation for PostgreSQL, which detects possible
-- interference between concurrent transactions, can produce false positives
-- in psql, create the following table
CREATE TABLE users(
id SERIAL NOT NULL PRIMARY KEY,
username VARCHAR NOT NULL
);
@alphp
alphp / cif_validation.php
Last active May 12, 2022 08:53
Spanish CIF validation (PHP)
<?php
function cif_validation ($cif) {
$cif = strtoupper($cif);
if (preg_match('~(^[XYZ\d]\d{7})([TRWAGMYFPDXBNJZSQVHLCKE]$)~', $cif, $parts)) {
$control = 'TRWAGMYFPDXBNJZSQVHLCKE';
$nie = array('X', 'Y', 'Z');
$parts[1] = str_replace(array_values($nie), array_keys($nie), $parts[1]);
$cheksum = substr($control, $parts[1] % 23, 1);
return ($parts[2] == $cheksum);
} elseif (preg_match('~(^[ABCDEFGHIJKLMUV])(\d{7})(\d$)~', $cif, $parts)) {
@donnykurnia
donnykurnia / .htaccess
Created April 1, 2013 08:52
.htaccess for 503 maintenance page
ErrorDocument 503 /index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.html [R=503,L]

Phoenix 1.4.x to 1.5.0 upgrade instructions

Phoenix 1.5 requires Elixir >= 1.7. Be sure your existing version is up to date by running elixir -v on the command line.

Install the new phx.new project generator

$ mix archive.uninstall phx_new
$ mix archive.install hex phx_new 1.5.0
@cronfy
cronfy / .htaccess
Last active July 23, 2021 19:44 — forked from donnykurnia/.htaccess
.htaccess 503 Техническое обслуживание сайта (maintenance page)
AddDefaultCharset utf-8
ErrorDocument 503 /maintenance.html
RewriteEngine On
RewriteBase /
# uncomment and set your ip to allow your ip to enter
#RewriteCond %{REMOTE_ADDR} !1\.2\.3\.4
# block requests to site, but allow let's encypt generation
@jasondmoss
jasondmoss / stripNamespaceFromClassName.php
Last active February 18, 2021 00:06
Strip the namespace from the class to get the actual class name
<?php
/**
* Strip the namespace from the class to get the actual class name
*
* @param string $obj Class name with full namespace
*
* @return string
* @access public
*/
@bitjockey42
bitjockey42 / 00_OSX_Docker_Machine_Setup.md
Last active November 9, 2020 13:49 — forked from andystanton/Start up local Docker Machine on OSX automatically.md
Use native virtualization on OS X docker with xhyve

What this?

So one of the painful points of using docker on OS X is that you need to run a virtualbox VM, which often suffers from performance issues. With xhyve, a OS X virtualization system, and docker-machine-xhyve you can now have docker use the native OS X hypervisor to run containers.

No more dealing with virtualbox shenanigans!

In this script, I've also set up a way to autoconfigure terminal sessions to load docker's environment vars (dependent on docker-machine) so you do not have to run eval $(docker-machine env whatever) every time you open a new terminal window.

Requirements