Skip to content

Instantly share code, notes, and snippets.

@andreaseriksson
andreaseriksson / convert_to_verified_routes.ex
Last active March 31, 2024 12:29
This is a mix task for converting old Phoenix routes to new verified routes
defmodule Mix.Tasks.ConvertToVerifiedRoutes do
@shortdoc "Fix routes"
use Mix.Task
@regex ~r/(Routes\.)(.*)_(path|url)\(.*?\)/
@web_module MyAppWeb
def run(_) do
Path.wildcard("lib/**/*.*ex")
// Keep the tab busy with audio.
const audioCtx = new AudioContext();
const gainNode = audioCtx.createGain();
gainNode.gain.value = 0.1;
gainNode.connect(audioCtx.destination);
const oscillatorNode = audioCtx.createOscillator();
oscillatorNode.type = "square";
@atomkirk
atomkirk / ecto-url-validation.md
Last active February 14, 2024 07:20
validate url in elixir

Here's an ecto changeset validation for urls:

  @doc """
  validates field is a valid url

  ## Examples
    iex> Ecto.Changeset.cast(%ZB.Account{}, %{"website" => "https://www.zipbooks.com"}, [:website])
    ...> |> Utils.Changeset.validate_url(:website)
    ...> |> Map.get(:valid?)
@samrocketman
samrocketman / libimobiledevice_ifuse_Ubuntu.md
Last active January 11, 2024 22:47
On Ubuntu 16.04, since iOS 10 update, libimobiledevice can't connect to my iPhone. This is my attempt to document a fix.

Why this document?

I upgraded my iPhone 5s to iOS 10 and could no longer retrieve photos from it. This was unacceptable for me so I worked at achieving retrieving my photos. This document is my story (on Ubuntu 16.04).

The solution is to compile libimobiledevice and ifuse from source.

Audience

Who is this guide intended for?

@JohannesBuchner
JohannesBuchner / rsync_on_change.sh
Created December 15, 2015 16:59
rsync loop that updates remote directory when local directory changes (using inotify)
while true
do
rsync -avz ./ user@host:remote/directory/
inotifywait -r ./
done
@PurpleBooth
PurpleBooth / README-Template.md
Last active May 22, 2024 13:17
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@wwwtyro
wwwtyro / gist:beecc31d65d1004f5a9d
Created March 16, 2015 05:54
GLSL ray-sphere intersection
float raySphereIntersect(vec3 r0, vec3 rd, vec3 s0, float sr) {
// - r0: ray origin
// - rd: normalized ray direction
// - s0: sphere center
// - sr: sphere radius
// - Returns distance from r0 to first intersecion with sphere,
// or -1.0 if no intersection.
float a = dot(rd, rd);
vec3 s0_r0 = r0 - s0;
float b = 2.0 * dot(rd, s0_r0);
@Mayeu
Mayeu / list.md
Last active June 14, 2016 07:09
Wordpress tools list focused on local dev, from a guy that do not use Wordpress

Warning: I am not a Wordpress dev or user, I try to avoid working with it as much as possible. So some asumptions may be trolling or totally wrong because I overlooked something. You may give feedback if you wish.

Assumptions

Recently I got to work with a Wordpress instance. When I work, I work locally, but Wordpress is thought like an online tools only, for example:

  • Working locally mean that you need to modify some DB fields when you export
@prwhite
prwhite / Makefile
Last active May 16, 2024 05:50
Add a help target to a Makefile that will allow all targets to be self documenting
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
# Everything below is an example
target00: ## This message will show up when typing 'make help'
@echo does nothing
@henrik
henrik / authentication.rb
Created September 10, 2013 14:24
A precursor of http://github.com/henrik/autho. Simple Rails-less authentication model. Assumes an API compatible with ActiveRecord and Rails' has_secure_password.
require "bcrypt"
require "attr_extras"
class Authentication
pattr_initialize :finder, :email, :password
def self.digest(unencrypted_password)
BCrypt::Password.create(unencrypted_password)
end