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?
//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;
@oshea00
oshea00 / BulkInsertAll.cs
Created April 24, 2013 19:57
Use SQLBulkLoad with linq-toSQL in LinqPad
// Add this to LinqPad "C# Program"
// Example use:
// Insead of this: (create a List<CS_POSITION>)
// CS_POSITIONs.InsertOnSubmit(position);
// This:
// positions.Add(position);
//
// Then instead of this:
// SubmitChanges()
// This:
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;
// 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 / kabsch.py
Last active April 4, 2024 04:51
3D best-fit using Kabsch algorithm
import numpy as np
from math import sqrt
scaling = False
# Implements Kabsch algorithm - best fit.
# Supports scaling (umeyama)
# Compares well to SA results for the same data.
# Input:
# Nominal A Nx3 matrix of points
@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')