text:
class User < ActiveRecord::Base
  def projects
    gitlab.projects(page: 1, per_page: 100)
  end

  def gitlab
    Gitlab.client(private_token: self.private_token)
  end
end

redpajama_set_name: RedPajamaGithub


text:
import { expect } from "chai";
import * as _ from "lodash";
import * as sinon from "sinon";

import { FirebaseError } from "../../../error";
import * as firestore from "../../../init/features/firestore";
import * as indexes from "../../../init/features/firestore/indexes";
import * as rules from "../../../init/features/firestore/rules";
import * as requirePermissions from "../../../requirePermissions";
import * as apiEnabled from "../../../ensureApiEnabled";
import * as checkDatabaseType from "../../../firestore/checkDatabaseType";

describe("firestore", () => {
  const sandbox: sinon.SinonSandbox = sinon.createSandbox();
  let checkApiStub: sinon.SinonStub;
  let checkDbTypeStub: sinon.SinonStub;

  beforeEach(() => {
    checkApiStub = sandbox.stub(apiEnabled, "check");
    checkDbTypeStub = sandbox.stub(checkDatabaseType, "checkDatabaseType");

    // By default, mock Firestore enabled in Native mode
    checkApiStub.returns(true);
    checkDbTypeStub.returns("CLOUD_FIRESTORE");
  });

  afterEach(() => {
    sandbox.restore();
  });

  describe("doSetup", () => {
    it("should require access, set up rules and indices, ensure cloud resource location set", async () => {
      const requirePermissionsStub = sandbox
        .stub(requirePermissions, "requirePermissions")
        .resolves();
      const initIndexesStub = sandbox.stub(indexes, "initIndexes").resolves();
      const initRulesStub = sandbox.stub(rules, "initRules").resolves();

      const setup = { config: {}, projectId: "my-project-123", projectLocation: "us-central1" };

      await firestore.doSetup(setup, {}, {});

      expect(requirePermissionsStub).to.have.been.calledOnce;
      expect(initRulesStub).to.have.been.calledOnce;
      expect(initIndexesStub).to.have.been.calledOnce;
      expect(_.get(setup, "config.firestore")).to.deep.equal({});
    });

    it("should error when cloud resource location is not set", async () => {
      const setup = { config: {}, projectId: "my-project-123" };

      await expect(firestore.doSetup(setup, {}, {})).to.eventually.be.rejectedWith(
        FirebaseError,
        "Cloud resource location is not set"
      );
    });

    it("should error when the firestore API is not enabled", async () => {
      checkApiStub.returns(false);

      const setup = { config: {}, projectId: "my-project-123" };

      await expect(firestore.doSetup(setup, {}, {})).to.eventually.be.rejectedWith(
        FirebaseError,
        "It looks like you haven't used Cloud Firestore"
      );
    });

    it("should error when firestore is in the wrong mode", async () => {
      checkApiStub.returns(true);
      checkDbTypeStub.returns("CLOUD_DATASTORE_COMPATIBILITY");

      const setup = { config: {}, projectId: "my-project-123" };

      await expect(firestore.doSetup(setup, {}, {})).to.eventually.be.rejectedWith(
        FirebaseError,
        "It looks like this project is using Cloud Datastore or Cloud Firestore in Datastore mode."
      );
    });
  });
});


text:
<?php

namespace psesd\sensorHub\controllers;

use Yii;
use yii\web\NotFoundHttpException;
use psesd\sensorHub\models\Contact;
use canis\registry\models\Registry;
use yii\data\ActiveDataProvider;
use yii\data\ArrayDataProvider;
use psesd\sensorHub\components\instances\ProviderInstance;

class ContactController extends Controller
{

    public function actionDelete()
    {
        if (!empty($_GET['id'])) {
            $this->params['model'] = $model = Contact::find()->where(['id' => $_GET['id']])->one();
        }
        if (empty($model)) {
            throw new NotFoundHttpException("Contact not found");
        }
        if (!empty($_GET['confirm'])) {
            if ($model->delete()) {
                Yii::$app->response->task = 'message';
                Yii::$app->response->success = 'Contact was deleted!';
            } else {
                Yii::$app->response->task = 'message';
                Yii::$app->response->error = 'An error occurred while deleting the contact';
            }
            Yii::$app->response->trigger = [['refresh', '.sensor-viewer']];
            return;
        }

        Yii::$app->response->labels['submit'] = 'Delete';
        Yii::$app->response->taskOptions = ['title' => 'Delete Contact', 'isConfirmDeletion' => true];
        Yii::$app->response->task = 'dialog';
        Yii::$app->response->view = 'delete';
    }

    public function actionUpdate()
    {
        if (!empty($_GET['id'])) {
            $this->params['model'] = $model = Contact::find()->where(['id' => $_GET['id']])->one();
        }
        if (empty($model)) {
            throw new NotFoundHttpException("Contact not found");
        }
        // $this->params['scenario'] = $scenario = 'update';

        if (!empty($_POST)) {
            $this->params['model']->load($_POST);
            if ($this->params['model']->save()) {
                Yii::$app->response->success = 'Contact \'' . $model->descriptor .'\' updated!';
                Yii::$app->response->trigger = [['refresh', '.sensor-viewer']];
                return;
            }
        }
        Yii::$app->response->view = 'create';
        Yii::$app->response->task = 'dialog';
        Yii::$app->response->labels['submit'] = 'Update';
        Yii::$app->response->taskOptions = ['title' => 'Update Contact', 'width' => '800px'];
    }

    public function actionCreate()
    {
        if (!empty($_GET['objectId'])) {
            $this->params['objectModel'] = $objectModel = Registry::getObject($_GET['objectId']);
        }
        if (empty($objectModel)) {
            throw new NotFoundHttpException("Object not found");
        }
        $this->params['model'] = $model = new Contact;
        $model->object_id = $objectModel->id;
        if (!empty($_POST)) {

            $this->params['model']->load($_POST);
            if ($this->params['model']->save()) {
                Yii::$app->response->success = 'Contact \'' . $model->descriptor .'\' created!';
                Yii::$app->response->trigger = [['refresh', '.sensor-viewer']];
            }
        }
        Yii::$app->response->view = 'create';
        Yii::$app->response->task = 'dialog';
        Yii::$app->response->labels['submit'] = 'Create';
        Yii::$app->response->taskOptions = ['title' => 'Add Contact', 'width' => '800px'];
    }

    public function actionView()
    {
        if (!empty($_GET['id'])) {
            $this->params['model'] = $model = Contact::find()->where(['id' => $_GET['id']])->one();
        }
        if (empty($model)) {
            throw new NotFoundHttpException("Contact not found");
        }
        Yii::$app->response->view = 'view';
        Yii::$app->response->task = 'dialog';
        Yii::$app->response->taskOptions = ['title' => 'Contact', 'width' => '400px', 'isForm' => false];
    }
}
?>


text:
package server

import (
	"net/http"
	"pharos/services/store"
	"strconv"
	"time"

	"github.com/gin-gonic/gin"
)

func createPost(ctx *gin.Context) {
	post := ctx.MustGet(gin.BindKey).(*store.Post)
	user, err := currentUser(ctx)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	if err := store.AddPost(user, post); err != nil {
		ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"msg":  "Post created successfully.",
		"data": post,
	})
}

func indexPosts(ctx *gin.Context) {
	user, err := currentUser(ctx)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	if err := store.FetchUserPosts(user); err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"msg":  "Posts fetched successfully.",
		"data": user.Posts,
	})
}

func updatePost(ctx *gin.Context) {
	jsonPost := ctx.MustGet(gin.BindKey).(*store.Post)
	user, err := currentUser(ctx)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": InternalServerError})
		return
	}
	dbPost, err := store.FetchPost(jsonPost.ID)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	if user.ID != dbPost.UserID {
		ctx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "Not authorized."})
		return
	}
	jsonPost.ModifiedAt = time.Now()
	if err := store.UpdatePost(jsonPost); err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": InternalServerError})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"msg":  "Post updated successfully.",
		"data": jsonPost,
	})
}

func deletePost(ctx *gin.Context) {
	paramID := ctx.Param("id")
	id, err := strconv.Atoi(paramID)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Not valid ID."})
		return
	}
	user, err := currentUser(ctx)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": InternalServerError})
		return
	}
	post, err := store.FetchPost(id)
	if err != nil {
		ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	if user.ID != post.UserID {
		ctx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "Not authorized."})
		return
	}
	if err := store.DeletePost(post); err != nil {
		ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{"msg": "Post deleted successfully."})
}