Skip to content

Instantly share code, notes, and snippets.

View radzserg's full-sized avatar

Sergey Radzishevskii radzserg

View GitHub Profile
@radzserg
radzserg / gist:5915803
Created July 3, 2013 06:13
yii migration with cahnge command
<?php
namespace yii\db;
class Migration extends \yii\db\MigrationBase
{
const DIRECTION_UP = 'up';
const DIRECTION_DOWN = 'down';
@radzserg
radzserg / gist:7996591
Last active December 31, 2015 13:59
Yii CDbFixtureManager do not update sequence after loading data
<?php
public function loadFixture($tableName)
{
$fileName=$this->basePath.DIRECTORY_SEPARATOR.$tableName.'.php';
if(!is_file($fileName))
return false;
$rows=array();
$schema=$this->getDbConnection()->getSchema();
$builder=$schema->getCommandBuilder();
@radzserg
radzserg / AssetManager.php
Created January 3, 2014 11:10
init function
public function init()
{
parent::init();
$this->basePath = Yii::getAlias($this->basePath);
if (!is_dir($this->basePath)) {
throw new InvalidConfigException("The directory does not exist: {$this->basePath}");
} elseif (!is_writable($this->basePath)) {
throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}");
} else {
$this->basePath = realpath($this->basePath);
@radzserg
radzserg / meteor pagination class
Last active October 19, 2016 20:34
meteor pagination class
namespace('App.data')
###
Meteor pagination class
Usage
UsersController = RouteController.extend
waitOn: ->
@page = @params.query.page || 1
@pagination = new App.data.Pagination(Users, selector, {page: @page})
@radzserg
radzserg / upload_manager_interface.ex
Last active October 10, 2016 12:26
Upload Manager Interface
defmodule App.UploadManager.Behavior do
@doc """
Check if file exists
"""
@callback exists?(String.t) :: :ok | {:error, String.t}
@doc """
Save file to storage
"""
@radzserg
radzserg / upload_manager_local.ex
Last active October 10, 2016 12:26
Upload manager for local storage - /lib/myapp/upload_manager/local.ex
defmodule App.UploadManager.Local do
@behaviour App.UploadManager.Behavior
@config Application.get_env(:app, :file_manager)[:local]
@doc """
Check if file exists
"""
def exists?(destination) do
destination = build_path(destination)
@radzserg
radzserg / s3.ex
Last active October 10, 2016 12:26
AWS S3 upload manager /lib/myapp/upload_manager/s3.ex
defmodule App.UploadManager.S3 do
@behaviour App.UploadManager.Behavior
@config Application.get_env(:App, :file_manager)[:s3]
alias ExAws.S3
@doc """
Check if file exists on S3 bucket
@radzserg
radzserg / image_migration.ex
Created September 26, 2016 15:16
Migration for image model.
defmodule App.Repo.Migrations.CreateImage do
use Ecto.Migration
def change do
create table(:images) do
add :type, :string, null: false
add :path, :string, null: false
add :mime, :string
add :size, :integer
add :width, :integer
defmodule App.Image do
use App.Web, :model
alias App.Image
alias App.Repo
schema "images" do
field :type, :string
field :path, :string
field :mime, :string
@radzserg
radzserg / pact.ex
Last active September 27, 2016 13:37
pact config
defmodule App.Pact do
@moduledoc """
Application registry container
"""
use Pact
case Mix.env do
:dev ->
register "upload_manager", App.UploadManager.S3