Skip to content

Instantly share code, notes, and snippets.

@jmacqueen
jmacqueen / application.js
Created October 6, 2016 16:06
Create an Ember application instance that can be imported into any file. Useful for container lookups in files outside of the usual hierarchy.
// app/instance-initializers/application.js
import appInst from 'appName/utils/application'
export function initialize( appInstance ) {
appInst.instance = appInstance
}
export default {
name: 'application',
initialize
};
@imranismail
imranismail / readme.md
Last active April 23, 2017 12:16
Tips on Elixir that you might not know of

Elixir Tips and Tricks That You Might Not Know Of

SaaS/Multitenant Migrations with Ecto

defmodule App.Team do
  use App, :schema

  ...
@imranismail
imranismail / attachment.ex
Created January 1, 2017 16:54
Media Prototype
defmodule Blog.Attachment do
use Blog, :schema
@primary_key {:id, :binary_id, autogenerate: true}
@storage_path "attachments"
schema "attachments" do
field :file, :any, virtual: true
belongs_to :post, Post
@imranismail
imranismail / README.md
Last active July 28, 2017 08:48
Repo composition

Repo Composition

Motive

Ecto.Repo by default doesn't allow overrides. So when you need to compose functions but maintain an API parity with the Ecto.Repo. You'd need to compose the functions in another module and things can get messy really fast that way.

Can't invoke super

== Compilation error on file lib/app/repo.ex ==
** (CompileError) lib/app/repo.ex:6: no super defined for all/2 in module App.Repo. Overridable functions available are:
@rodrigoddalmeida
rodrigoddalmeida / ecto_soft_delete.exs
Last active August 29, 2017 16:47
Soft Delete in Ecto
model = Repo.get!(Model, id)
Ecto.Changeset.change(model)
|> Ecto.Model.Timestamps.put_timestamp(:deleted_at, Ecto.DateTime, true)
|> Repo.update
@Vercoutere
Vercoutere / 1.Summary.md
Last active November 15, 2018 09:34
Laravel 5 middleware class that sets a context in a multi-tenant app + updated version for easier testing with example testcase.
@puckbag
puckbag / guzzle-custom-curlfactory.php
Last active November 1, 2019 23:06
Custom Guzzle CurlFactory
<?php
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlFactory;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Handler\CurlMultiHandler;
use GuzzleHttp\Handler\EasyHandle;
@heikomat
heikomat / js_basics.md
Last active December 10, 2020 10:41
Introduction to ioc, di, functions, scopes, callbacks, promises and async/await

Inversion of Control via Dependency Injection

Without dependency injection

engine.ts

export class Engine {}

car.ts

@febridev
febridev / controller.php
Created April 3, 2017 16:18
eloquent laravel group by year
// Carbon
use Carbon\Carbon;
$visitorTraffic = PageView::select('id', 'title', 'created_at')
->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('Y'); // grouping by years
//return Carbon::parse($date->created_at)->format('m'); // grouping by months
});
@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