Skip to content

Instantly share code, notes, and snippets.

@kflu
kflu / ExpressionTreeLambdaToAssembly.cs
Last active November 28, 2018 14:49
Dump expression tree lambda into assembly for easy IL inspection using ildasm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Linq.Expressions;
using System.Reflection.Emit;
using System.IO;
public class WebClientEx : WebClient
{
public WebClientEx(CookieContainer container)
{
this.container = container;
}
private readonly CookieContainer container = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
Clear-Item -Path alias:dir
function dir
{
Invoke-Expression "cmd /c dir $args"
}
Clear-Item -Path alias:cd
New-Alias -Name cd -Value Push-Location
$env:Path = ".\;$env:Path"
@kflu
kflu / checkip.py
Created August 22, 2012 05:53
check my IP address
import logging
import urllib2
import re
from contextlib import closing
def get_ip(url = "http://checkip.dyndns.org/"):
'''Get local machine (or router)'s external IP from a IP checking web
service.
url: the URL of the IP checking service. Default to
@kflu
kflu / binary_tree_find_path.py
Created August 4, 2012 18:18
Find all paths in a binary tree that the nodes on the path sums up to a specified vale.
"""Find all paths in a binary tree that the nodes on the path sums up to a specified vale.
"""
from collections import deque
def find_path(T,X):
"""
On each node it visits, it marks the node's parent. This is for tracing
upwards.
"""
res = []
@kflu
kflu / find_path.py
Created August 2, 2012 05:58
Finding path between two nodes in a directed graph using BFS.
from Queue import Queue
def find_path(E, V, n1, n2):
"""Find path between n1,n2 of a directed graph"""
for n in E:
n.from_ = None
q = Queue()
q.put(n1)
found = False
while not q.empty():
@kflu
kflu / CheckTreeBalance.cs
Last active October 7, 2015 22:24
Check if a binary tree is balance, i.e., all leaf nodes are on levels which difference does not exceed 1.
// Deprecated in favor of https://github.com/puzzl3r/puzzles/tree/master/CheckTreeBalance
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
@kflu
kflu / MyQueue.cs
Created August 2, 2012 03:13
Using stacks to implement a Queue.
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
@kflu
kflu / FindLongestPalindrome.cs
Created July 11, 2012 00:34
find longest palindrome
using System.Text;
using System;
using System.Diagnostics;
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
@kflu
kflu / SortedMatrix.cs
Created July 8, 2012 22:17
Find a value in a sorted matrix
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace ConsoleApplication4
{
/// <summary>
///
/// </summary>
/// <remarks>