Skip to content

Instantly share code, notes, and snippets.

View mii9000's full-sized avatar

ibrahim mii9000

View GitHub Profile
@mii9000
mii9000 / webapiclientip.cs
Last active June 12, 2023 08:12
How to get Client IP from a request in Web API #webapi
using System.Net.Http;
using System.ServiceModel.Channels;
using System.Web;
using System.Web.Http;
namespace Trikks.Controllers.Api
{
public class IpController : ApiController
{
public string GetIp()
@mii9000
mii9000 / dynamicwebapirepo.cs
Last active August 29, 2015 14:06
Thin convention based WebAPI repository
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Net.Http;
using System.Threading.Tasks;
using System.Net.Http.Headers;
namespace WebApp
@mii9000
mii9000 / clear.bat
Created December 1, 2014 13:04
remove-aspnet-tempcache
@ECHO OFF
ECHO Performing IIS Reset
IISRESET
ECHO Deleting Cache
FOR /D %%i IN (%LOCALAPPDATA%\Microsoft\WebsiteCache\*) DO RD /S /Q "%%i"
DEL /Q %LOCALAPPDATA%\Microsoft\WebsiteCache\*.*
FOR /D %%i IN (%LOCALAPPDATA%\Temp\VWDWebCache\*) DO RD /S /Q "%%i"
DEL /Q %LOCALAPPDATA%\Temp\VWDWebCache\*.*
@mii9000
mii9000 / gh-code.css
Created July 28, 2015 07:36
GitHub's CSS for code block with syntax highlighting
/* Usage sample: http://jsfiddle.net/ibrahimislam/c9snLshw/2/ */
/* Get the markdown parsed from api.github.com/markdown */
.highlight pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
@mii9000
mii9000 / ideas.md
Last active August 29, 2015 14:28 — forked from tsaqib/ideas.md
Ideas that you can use for hackathons, competitions and research.

Ideas

I have collected and moderated these ideas from various public sources and put into one place so that problem solvers and solution developers may find inspirations. Because I wish to update it regularly, I have setup as a single page wiki. You may try these ideas on hackathons/competitions/research; some are quite intense problems and some are not. Many of the problems were prepared keeping Dhaka/Bangladesh in mind, but of course can be applied to just about any underdeveloped/developing and sometimes developed countries.

Categories:
  • Eradicate Extreme Poverty and Hunger
  • Education
  • Healthcare
  • Governance
@mii9000
mii9000 / gist:d5e6405233d749a3d5a2
Created October 23, 2015 17:27 — forked from dshookowsky/gist:6529765
Reader object to expando
private dynamic SqlDataReaderToExpando(DbDataReader reader)
{
var expandoObject = new ExpandoObject() as IDictionary<string, object>;
for (var i = 0; i < reader.FieldCount; i++)
expandoObject.Add(reader.GetName(i), reader[i]);
return expandoObject;
}
@mii9000
mii9000 / player.js
Created November 8, 2015 21:02 — forked from revolunet/player.js
basic nodejs mp3 player
var async = require('async');
var lame = require('lame');
var fs = require('fs');
var Speaker = require('speaker');
var volume = require("pcm-volume");
var audioOptions = {
channels: 2,
bitDepth: 16,
sampleRate: 44100,
@mii9000
mii9000 / WinRTXamlQueryExtensions.cs
Last active November 27, 2015 11:25
Extensions method that searches up or down VisualTree from the source element
public static class WinRTXamlQuery
{
/// <summary>
/// Searches descendants recursively down to the last one
/// </summary>
/// <typeparam name="T">FrameworkElement type expected</typeparam>
/// <param name="Source">FrameworkElement searched from</param>
/// <param name="Name">Name of the control to expect</param>
public static IEnumerable<T> GetDescendents<T>(this FrameworkElement Source, string Name = "")
{
@mii9000
mii9000 / DateTimeCulture.cs
Created March 24, 2016 14:21
Set datetime of a culture application wide
protected void Application_BeginRequest(Object sender, EventArgs e)
{
//Set Custom Culture
CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.DateSeparator = "/";
Thread.CurrentThread.CurrentCulture = newCulture;
}
@mii9000
mii9000 / ReflectionDbSet.cs
Created March 24, 2016 14:25
Example of using Reflection to set DbSets passing in same DbContext to repositories. P.S. DI was not used in this project this had to resort to this.
//Gets the DbSets and sets their properties to equivalent instances passing in same DbContext
this.GetType().GetProperties()
.Where(p => p.PropertyType.GetGenericTypeDefinition() == typeof(GenericRepository<>))
.ToList()
.ForEach(dbset =>
{
Type EntityType = dbset.PropertyType.GenericTypeArguments[0];
Type GenericRepoType = dbset.PropertyType.GetGenericTypeDefinition().MakeGenericType(EntityType);
ConstructorInfo ctor = GenericRepoType.GetConstructor(new[] { typeof(ApplicationDbContext) });
object GenericRepoInstance = ctor.Invoke(new object[] { DbContext });