Skip to content

Instantly share code, notes, and snippets.

View ericpony's full-sized avatar

ericpony ericpony

  • University of Oxford
  • Oxford
View GitHub Profile
@ericpony
ericpony / video-info.cs
Last active November 25, 2022 17:27
Retrieve media info using C#
/*
* http://stackoverflow.com/questions/6215185/getting-length-of-video
*/
using DirectShowLib;
using DirectShowLib.DES;
using System.Runtime.InteropServices;
...
import leon.lang._
import leon.collection._
abstract class Stack[T] {
def empty : Stack[T]
def pop : (Option[T], Stack[T])
def push (e : T) : Stack[T]
def size : BigInt
}
@echo off
REM Windows batch file to run jsctags
REM
REM Assumes node.exe is in your %PATH%.
REM git clone --recursive git://github.com/mozilla/doctorjs.git d:\opt\doctorjs
REM Note: Currently, the latest jsctags only works with older versions of node
REM To manage multiple versions of node on the same machine, use `n`.
REM `npm install -g n`
REM
REM Alternatively:
@ericpony
ericpony / RecursiveVersion.java
Created December 6, 2014 11:56
Copy List with Random Pointer (with HashMap and n recursive calls)
/**
* Definition for singly-linked list with a random pointer.
* class RandomListNode {
* int label;
* RandomListNode next, random;
* RandomListNode(int x) { this.label = x; }
* };
*/
public class RecursiveVersion {
public RandomListNode copyRandomList(RandomListNode head) {
@ericpony
ericpony / copyRandomList.cpp
Created December 6, 2014 11:09
Copy List with Random Pointer
/**
* Definition for singly-linked list with a random pointer.
* struct RandomListNode {
* int label;
* RandomListNode *next, *random;
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {}
* };
*/
class Solution {
public:
/* matchhere: search for regexp at beginning of text */
int matchhere(char *regexp, char *text)
{
if (regexp[0] == '\0')
return 1;
if (regexp[1] == '*')
return matchstar(regexp[0], regexp+2, text);
if (regexp[0] == '$' && regexp[1] == '\0')
return *text == '\0';
if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text))
@ericpony
ericpony / Regex_Parser.scala
Created September 24, 2014 15:17
A demonstration of the CPS coding style
object Main {
class Regex
case class Literal(s: String) extends Regex
case class Concat(r1: Regex, r2: Regex) extends Regex
case class Choice(r1: Regex, r2: Regex) extends Regex
case class Star(r: Regex) extends Regex
def accept(regex: Regex, chars: Seq[Char], k: Seq[Char] => Boolean): Boolean =
regex match {
function interpret(form, env, ctx){
if(form instanceof Array){
switch(form[0]){
case 'lambda': {
var params = form[1];
var body = form[2];
return ctx(function(ctx){ return function() {
var e = Object.create(env);
for(var j = 0; j < params.length; j++)
e[params[j]] = arguments[j];
@ericpony
ericpony / Linked List Cycle II.java
Last active August 29, 2015 14:01
Given a linked list, return the node where a cycle begins, or return null if there is no cycle.
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
@ericpony
ericpony / Maximal Rectangle in Histogram.java
Last active August 29, 2015 14:01
Optimal solution to finding the area of the largest rectangle in histogram. (http://oj.leetcode.com/problems/largest-rectangle-in-histogram)
public class Solution {
/**
* This is a O(n) algorithm for finding the area of the largest rectangle
* in histogramand and is a simple version of Daveed V's optimal algorithm
* for finding the largest rectangle in a 2D matrix.
* See https://gist.github.com/ericpony/15c1a126980f36652e6a for details.
*/
public int largestRectangleArea(int[] height) {
if(height==null || height.length==0)