Skip to content

Instantly share code, notes, and snippets.

View telliott99's full-sized avatar

Tom Elliott telliott99

View GitHub Profile
from math import e, pi, sqrt
def get_xvalues(a,b,N):
dist = 1.0*b - 1.0*a
dx = dist/N
half = dx/2.0
R = [(a + dx * n + half) for n in range(N)]
return R, dx
def integrate(a,b,f,N=100):
from matplotlib import pyplot as plt
import numpy as np
p = 81
q = 219
def f(x):
return x**(p-1)*(1-x)**(q-1)
X = np.linspace(0,1,1000)
from random import choice as ch
R = range(1,366)
# report doubles, triples for a single run
def analyze(L):
L.sort()
rD = dict()
i = 0
while i < len(L) - 1: # up to penultimate item
v = L[i]
from random import choice as ch
R = range(1,366)
# report doubles, triples for a single run
def analyze(L):
L.sort()
rD = dict()
i = 0
while i < len(L) - 2: # up to penultimate item
v = L[i]
func merge(a1: [Int], _ a2: [Int]) -> [Int] {
// a1 and a2 are sorted already
var ret: [Int] = []
var i: Int = 0
var j: Int = 0
while i < a1.count || j < a2.count {
if j == a2.count {
if i == a1.count - 1 {
ret.append(a1[i])
}
@telliott99
telliott99 / script.py
Created December 17, 2015 01:27
testing with python
import os, subprocess, time
for i in range(100):
print(str(i+1))
cmd = 'open -a "MyApp"'
p = subprocess.Popen(cmd, shell=True)
pid,ecode = os.waitpid(p.pid, 0)
if ecode != 0:
print "error"
break
@telliott99
telliott99 / test.swift
Created December 17, 2015 01:25
pointer demo
import Foundation
func t() {
let a: [Int32] = [1,2,3,4,5]
let n = Int32(a.count)
Swift.print("Swift: a = \(a)")
let ptr = UnsafeMutablePointer<Int32>(a)
f1(ptr, n)
f2(ptr, n)
f1(ptr, n)
@telliott99
telliott99 / p1.c
Last active December 17, 2015 01:21
pointer demo
#include <stdio.h>
#include <math.h>
void f1(int *ptr, int n) {
printf("f1\n");
for (int i = 0; i < n; i++) {
printf("%d ", ptr[i]);
}
printf("\n");
}
@telliott99
telliott99 / openssl_aes.swift
Last active December 16, 2015 02:50
attempt at using SSL (failed)
import Foundation
func encrypt() {
let msg = "My messageXXXXXX"
let key = "my secret pwXXXX"
var keyBuffer = [UInt8](
count: 16,
repeatedValue: 0)
@telliott99
telliott99 / test.swift
Created December 14, 2015 23:45
test for Carthage
import Encryptor
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
let key = Key("mypassphrase")
key.stretch()
let e = Encryptor(key)
print("\(e)")
}