Instantly share code, notes, and snippets.

View numerical_int.py
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):
View gamma2.py
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)
View friends.py
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]
View friends.py
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]
View mergesort.swift
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])
}
View script.py
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
View test.swift
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)
View p1.c
#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");
}
View openssl_aes.swift
import Foundation
func encrypt() {
let msg = "My messageXXXXXX"
let key = "my secret pwXXXX"
var keyBuffer = [UInt8](
count: 16,
repeatedValue: 0)
View test.swift
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)")
}