Skip to content

Instantly share code, notes, and snippets.

@imgen
imgen / ListBackedResultSet.java
Last active March 11, 2022 09:47
A list backed result set
package org.sprocky.util;
import org.apache.commons.lang3.ArrayUtils;
import org.sprocky.NameMappingConvention;
import org.sprocky.ResultSetColumn;
import org.sprocky.ResultSetColumnIgnore;
import org.sprocky.impl.DefaultNameMappingConvention;
import java.io.InputStream;
import java.io.Reader;
package com.sigicn.widget;
import javax.inject.Inject;
import android.content.Context;
import android.os.Handler;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.AdapterView;
@imgen
imgen / BaseDal.cs
Created October 3, 2017 15:59
BaseDal new methods
using System.Collections.Generic;
using CreateAndRealize.Common;
using Dapper.Contrib.Extensions;
using SqlKata;
using System.Linq;
namespace CreateAndRealize.Aahk.Taxi.Infrastructure.Dal
{
public class BaseDal<TEntity>
where TEntity: class
@imgen
imgen / DotNetExtensions.cs
Created October 3, 2017 16:06
Extensions
public static IEnumerable<PropertyInfo> GetPropertiesWithAttributes<T, TAttr>(this object obj)
{
return GetPropertiesWithAttributes(obj, typeof(T), typeof(TAttr));
}
public static IEnumerable<PropertyInfo> GetPropertiesWithAttributes(this object obj, Type type, Type attrType)
{
return type.GetProperties()
.Where(x => x.GetCustomAttributes(true)
.Any(attr => attr.GetType() == attrType)
@imgen
imgen / QueueByStacks.cs
Last active October 23, 2018 14:36
Queue implemented in stacks
using System.Collections.Generic;
class QueueByStacks<T>
{
private Stack<T> _inStack, _outStack;
public QueueByStacks()
{
_inStack = new Stack<T>();
_outStack = new Stack<T>();
@imgen
imgen / boxstarter.ps1
Created November 30, 2018 09:22
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Alex Ho
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt:
# start http://boxstarter.org/package/nr/url?<URL-TO-RAW-GIST>
@imgen
imgen / MaxRectangleFinder.cs
Last active February 26, 2019 07:24
Calculate max rectangle area of a matrix of 0 and 1s
using System;
public class Program {
public static void Main() {
var matrices = new []{
new [] {
"00000",
"00000",
"00000",
"00000",
@imgen
imgen / MaxRectangleFinder.cs
Last active February 26, 2019 05:20
Minimal version of calculating max rectangle area of a matrix of 0 and 1s
using System;
using System.Linq;
public class Program {
public static void Main() {
var matrices = new []{
new [] {
"11011",
"01101",
"11110",
@imgen
imgen / MaxRectangleFinder.js
Created February 26, 2019 06:54
My friend CM's JavaScript version of calculating max rectangle area
const f = a => {
let max = 0;
const getLocalMax = a => {
let localMax = 0, maxJ = a[0].length -1;
const reset = i => {
const size = (i+1)*(maxJ+1);
if(size > localMax)
localMax = size;
}
using System;
using System.Linq.Expressions;
using System.Reflection;
public static class ReflectionUtils
{
public static MethodInfo GetMethod<TInput, TOutput>(Expression<Func<TInput, TOutput>> methodCallExpression) => GetMethodByLambdaExpression(methodCallExpression);
public static MethodInfo GetMethod<TInput>(Expression<Action<TInput>> methodCallExpression) => GetMethodByLambdaExpression(methodCallExpression);