Skip to content

Instantly share code, notes, and snippets.

@oshea00
oshea00 / quote.mb
Created October 8, 2011 21:31
Quote of the day
# Saturday #
===
>If you knew you could not fail, what would you do?
void Main()
{
var g = new Grid();
var w = new Window { Width = 420, Height = 440, Title = "Graph", Content = g};
var c = new Canvas { Background = Brushes.BlanchedAlmond };
DrawLine(200,10,200,390,c);
DrawLine(10,200,390,200,c);
double x1 = 150;
//Just a quick code snippet. I was interested in executing javascript from C#. So far, the two clear winners for a framework to do this are JInt and Jurrasic. Needless to say, the V8 Javascript.Net project is dead and doesn't even try to pretend otherwise...
//JScript .Net has been dead a long time - let's not even go there.
//Jurassic takes a bit more effort to integrate existing .Net objects into scripts as parameters, but makes perhaps is faster.
//JInt is the easiest to use and integrate (takes objects directly as parameters) - and for quick DSL-like scripting using Javascript - wins my vote.
using Jint;
using Jurassic;
using Newtonsoft.Json;
// flips.cpp : Defines the entry point for the console application.
//
#include "time.h"
#include "stdio.h"
#include "stdlib.h"
double f(int, int *i, int *hist);
int main(int argc, char* argv[] )
{
// flipfunc.c : Flips a coin
#include "time.h"
#include "stdio.h"
#include "stdlib.h"
double f(int, int *i, int *hist);
// Input: flips - how many times to flip the coin.
// Output:
import math
def isprime(n):
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
months = [0, 6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
def centuryOffset(c):
if c / 100 == 21:
return -2
if c / 100 == 20:
return 0
if c / 100 == 19:
return 1
@oshea00
oshea00 / filter.py
Last active May 1, 2018 19:27
Filter rows example
import io
f = open('somefile.txt','w')
freq = 2
rows = []
rows.append('row a')
rows.append('row b')
rows.append('row c')
rows.append('row d')
// Implements addition using bit operations (an adder)
// This was an answer to a playful Koan test for .Net Core.
// I resolved not to use google and work it out from basic
// boolean math principles. Could probably be simpler, but was
// a fun exercise.
public void AdditionWithoutPlusOrMinusOperator()
{
var adder = new Func<int,int,int>((a,b)=>{
int c = 0; // carry
from math import log2, pow
class Tree():
def __init__(this,value=None,left=None,right=None):
this.value = value
this.left = left
this.right = right
tree = Tree('*',
Tree('-',