Skip to content

Instantly share code, notes, and snippets.

View imranismail's full-sized avatar

Imran Ismail imranismail

View GitHub Profile
@Rich-Harris
Rich-Harris / service-workers.md
Last active March 15, 2024 03:03
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active February 25, 2024 17:35
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@rbishop
rbishop / README.md
Last active April 26, 2022 15:38
A super simple Elixir server for sending Server Sent Events to the browser.

Generate a new Elixir project using mix and add cowboy and plug as dependencies in mix.exs:

  defp deps do
    [
      {:cowboy, "~> 1.0.0"},
      {:plug, "~> 0.8.1"}
    ]
  end
@ahmadshah
ahmadshah / README.md
Last active January 6, 2021 15:21
Ecto Soft Delete

Soft Delete Ecto Repo

The goal is to support soft delete functionality in Ecto.Repo. With the suggestion by @imranismail, another repo is created and the remaining functionalities are delegate to the original MyApp.Repo.

The new repo get/2 and all/1 functions will exclude the soft deleted record by default. delete/1 and delete_all/1 will update the delete_at column by default instead of deleting.

Example

MyApp.Repo.get(MyApp.User, 1) //will return nil if record is in soft delete state
@mgwidmann
mgwidmann / ecto_polymorphism.ex
Last active September 29, 2020 14:45
Ecto Polymorphism
defmodule Ecto.Polymorphic do
defmacro __using__(_) do
quote do
require Ecto.Schema
import Ecto.Schema, except: [belongs_to: 2, belongs_to: 3]
import unquote(__MODULE__)
end
end
# Requires Erlang/OTP 19.0. Invoke as:
#
# iex --erl "-proto_dist Elixir.Epmdless -start_epmd false -epmd_module Elixir.Epmdless_epmd_client" --name frobozz3
# A module containing the function that determines the port number
# based on a node name.
defmodule Epmdless do
def dist_port(name) when is_atom(name) do
dist_port Atom.to_string name
end
@syamilmj
syamilmj / enum.ex
Created October 29, 2016 07:31
Add enum datatype support to Ecto
defmodule Inventory.Enum do
@moduledoc """
Provides macro to support Enum datatype with Ecto
## Usage
In your model:
import Inventory.Enum
defmodule Reactor.Service.Authenticator do
@behaviour Reactor.Contract.Service.Authenticator
@moduledoc """
User authentication service.
"""
use Reactor.Resolver, repositories: [:user]
alias Comeonin.Bcrypt, as: Comeonin
alias Reactor.Entity.User, as: UserEntity
@imranismail
imranismail / spectacle_app_extractor.sh
Created September 26, 2015 05:23
Spectacleapp Preference Extractor
for key in MoveToPreviousThird MoveToRightDisplay MakeLarger MoveToRightHalf MakeSmaller MoveToTopDisplay MoveToBottomDisplay MoveToTopHalf MoveToBottomHalf MoveToUpperLeft MoveToCenter MoveToUpperRight MoveToFullscreen MoveToLeftDisplay MoveToLeftHalf MoveToLowerLeft RedoLastMove MoveToLowerRight MoveToNextDisplay MoveToNextThird MoveToPreviousDisplay UndoLastMove; do
printf "defaults write com.divisiblebyzero.Spectacle ${key} -data ";
defaults read com.divisiblebyzero.Spectacle ${key} | sed 's/[^0-9a-f]//g';
done