Skip to content

Instantly share code, notes, and snippets.

View develohpanda's full-sized avatar
✌️
Chillin'

Opender Singh develohpanda

✌️
Chillin'
View GitHub Profile
@develohpanda
develohpanda / RoundToNearestXSeconds.txt
Created September 19, 2016 01:27
Power BI - Round to nearest x seconds
DateTime.From(Number.Round((Number.From([Time]) * 24 * 3600)/RoundToNearestXSecond, 0)*RoundToNearestXSecond/(24*3600))
@develohpanda
develohpanda / RunSync.cs
Created October 8, 2016 15:18
Run methods returning a Task synchronously, and return any output values. YOU SHOULD NEVER, EVER HAVE TO DO THIS, but if the need arises in that one rogue case....
public static class AsyncHelpers
{
/// <summary>
/// Execute an async method which has a void return value synchronously
/// </summary>
/// <param name="method">Task<T/> method to execute</param>
public static void RunSync(Func<Task> method)
{
Argument.CheckIfNull(method, nameof(method));
@develohpanda
develohpanda / FixDb.sql
Created April 27, 2017 01:51
Entity Framework reverse engineering making VS hang
UPDATE STATISTICS sys.syscolpars
UPDATE STATISTICS sys.sysschobjs
UPDATE STATISTICS sys.syssingleobjrefs
UPDATE STATISTICS sys.sysiscols
GO
@develohpanda
develohpanda / run-sqlcommand.ps1
Created July 4, 2017 04:40
Run SQL from Powershell
function Run-SqlCommand($serverName, $databaseName, $command, $timeoutSeconds = 30) {
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$serverName;Database=$databaseName;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $command
$SqlCmd.Connection = $SqlConnection
$SqlCmd.CommandTimeout = $timeoutSeconds
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
@develohpanda
develohpanda / update-rows-using-join.sql
Created July 11, 2017 03:43
Update Rows using join
update ft
set ft.description = 'test'
from firstTable ft
inner join secondTable st on
ft.id = st.id
@develohpanda
develohpanda / DeleteRowsAfterJoinCondition.sql
Created July 13, 2017 03:59
Delete after a join condition
DROP TABLE IF EXISTS #toDelete
SELECT bmi.* INTO #toDelete
FROM [dbo].[BCS_Main_Input_With_absence_Holiday_And_Wage_Elements] bmi
INNER JOIN @fiscalWeeksForRelease fw
on
fw.FISCAL_YEAR = bmi.Fiscal_Year
AND fw.FISCAL_WEEK = bmi.Fiscal_Week
INNER JOIN @StoresInRelease s
on
s.Store_Id = bmi.Store_ID
@develohpanda
develohpanda / keybase.md
Created February 7, 2018 00:37
keybase.md

Keybase proof

I hereby claim:

  • I am develohpanda on github.
  • I am ohpanda (https://keybase.io/ohpanda) on keybase.
  • I have a public key ASDZd5ZUSTt-dEnpHZxxxWwhncl2htpgKO4q9V82M7-9MAo

To claim this, I am signing this object:

@develohpanda
develohpanda / hoc-template.tsx
Created February 27, 2019 11:34 — forked from devdoomari3/hoc-template.tsx
Typescript higher order component (hoc) template
/* variation on https://medium.com/@DanHomola/react-higher-order-components-in-typescript-made-simple-6f9b55691af1 */
import * as React from 'react'
import { wrapDisplayName } from 'recompose'
// Props you want the resulting component to take (besides the props of the wrapped component)
interface ExternalProps {}
// Props the HOC adds to the wrapped component
export interface InjectedProps {}
@develohpanda
develohpanda / WeightedRandomSelectionWithLimitedAllocations.cs
Last active April 7, 2020 16:33
Weighted Random Selection With Limited Allocations - a modified implementation of the solution found at http://programmers.stackexchange.com/a/150642/244423
/// <summary>
/// Selects a random element from input list using the allocations remaining to sway selection
/// T must have AllocationRemaining, Weight and Id properties on it.
/// </summary>
public T SelectRandom<T>(List<T> objects)
{
int totalWeight = 0;
T selected = default(T);
foreach (T obj in objects)
{
@develohpanda
develohpanda / WeightedRandomSelection.cs
Last active April 7, 2020 16:34
Weighted Random Selection - a simplified implementation of the solution found at http://programmers.stackexchange.com/a/150642/244423
/// <summary>
/// Selects a random element from input list using the weights on T to sway selection.
/// T must have a Weight property on it.
/// </summary>
public T SelectRandom<T>(List<T> objects)
{
int totalWeight = 0;
T selected = default(T);
foreach (T obj in objects)
{