Skip to content

Instantly share code, notes, and snippets.

View Teddybiers's full-sized avatar

Taphatson Teddybiers

  • Bangkok, Thailand
View GitHub Profile
@Teddybiers
Teddybiers / Default.cshtml
Last active December 28, 2018 07:23
.NET Core Linq extension for paging.
<!-- You can place this file in Shared/Components/Pager/Default.cshtml -->
@model PagedResultBase
@{
var urlTemplate = Url.Action() + "?page={0}";
var request = ViewContext.HttpContext.Request;
foreach (var key in request.Query.Keys)
{
if (key == "page")
@Teddybiers
Teddybiers / ApplicationDbContext.cs
Created April 25, 2018 09:16
Default Query Scope
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Posts>().HasQueryFilter(p => p.IsActive);
}
// To ignore default filter
var posts = db.Posts
.IgnoreQueryFilters()
.ToList();
@Teddybiers
Teddybiers / gulpfile.js
Last active September 6, 2017 12:59
Sample gulp file for sass to css into wwwroot/css
var gulp = require("gulp"),
scss = require("gulp-sass");
gulp.task("sass", function () {
return gulp.src('Styles/*.scss')
.pipe(scss.sync().on('error', scss.logError))
.pipe(gulp.dest('wwwroot/css'));
});
gulp.task('watch', function () {
@Teddybiers
Teddybiers / Global.asax
Created August 22, 2017 08:43
Run Migration with deployment
protected void Application_Start()
{
var dbConfig = new Migrations.Configuration();
var migrator = new DbMigrator(dbConfig);
migrator.Update();
}
@Teddybiers
Teddybiers / WebApiConfig.cs
Created August 16, 2017 04:02
Default API Configure
using Microsoft.Web.Http.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Web.Http;
using System.Web.Http.Routing;
namespace USparkApi
{
@Teddybiers
Teddybiers / vs_code
Last active April 12, 2017 04:41
Set Visual Studio Code as a Git core editor
First of all, you have to install Visual Studio Command Line Tool by
To install Visual Studio Command Line Tool is press
⌘ + ^ + p and type "Install 'code' command in PATH"
- Restart your shell if you use Mac Terminal or iTerm2
or
- Restart your Visual Studio Code if you user Terminal in Visual Studio Code
After that, run "code --version" on your shell and see the result.
@Teddybiers
Teddybiers / modify_key.rb
Last active March 2, 2017 06:55
Map key and value after grouped in rails
Model.group(:foo).count(:bar).each_with_object({}) do |(key, value), memo|
#if you want to modify key
key = "modified_key"
memo[key] = value
end
@Teddybiers
Teddybiers / assign_attributes.rb
Last active March 2, 2017 06:54
Rescue an error when assign_attributes can't find an attribute in rails
def assign_attributes(*arguments)
super
rescue ActiveRecord::UnknownAttributeError => e # Error that you get from activerecord
# do something here!
end