Skip to content

Instantly share code, notes, and snippets.

/*** printenv.s ***/
// Description
// printenv - print the environment to stdout
// Synopsis
// printenv
// Build
// $ as --32 -o printenv.o printenv.s
// $ ld -m elf_i386 -o printenv printenv.o
/*** printenv.s ***/
// Description
// printenv - print the environment to stdout
// Synopsis
// printenv
// Build
// $ as --32 -o printenv.o printenv.s
// $ ld -m elf_i386 -o printenv printenv.o
/*** echo.s ***/
// Description
// echo - print arguments to stdout
// Synopsis
// echo [STRING]...
// Build
// $ as --32 -o echo.o echo.s
// $ ld -m elf_i386 -o echo echo.o
/*** echo.s ***/
// Description
// echo - print arguments to stdout
// Synopsis
// echo [STRING]...
// Build
// $ as --32 -o echo.o echo.s
// $ ld -m elf_i386 -o echo echo.o
@dstein64
dstein64 / helpers.s
Last active October 29, 2017 03:52
Helper macro and function for printenv.s and echo.s
.section .text
# ************************************
# * print macro
# * Caller is responsible for setting
# * %ecx and %edx, and saving %eax and
# * %ebx if necessary.
# ************************************
.macro print
movl $4, %eax
/*** printenv.c ***/
// Description
// printenv - print the environment to stdout
// Synopsis
// printenv
// Build
// $ gcc -o printenv printenv.c
#include <stdio.h>
@dstein64
dstein64 / echo.c
Last active October 24, 2017 16:58
/*** echo.c ***/
// Description
// echo - print arguments to stdout
// Synopsis
// echo [STRING]...
// Build
// $ gcc -o echo echo.c
#include <stdio.h>
# fails to properly return true when running sudo -s
function is_ssh_from_env() {
if [ -n "${SSH_TTY}" ] || \
[ -n "${SSH_CONNECTION}" ] || \
[ -n "${SSH_CLIENT}" ]; then
echo "true"
else
echo "false"
fi
}
import numpy as np
import numpy.ma as ma
import theano
from theano import tensor as T
floatX = theano.config.floatX
def getmask(D):
return ma.getmaskarray(D) if ma.isMA(D) else np.zeros(D.shape, dtype=bool)
def matrix_factorization_quux(
D, P, Q, steps=5000, alpha=0.0002, beta=0.02):
K = P.shape[1]
P = np.copy(P)
Q = np.copy(Q)
for step in xrange(steps):
for i in xrange(len(D)):
for j in xrange(len(D[i])):
if not getmask(D)[i, j]:
eij = D[i, j] - np.dot(P[i, :], Q[:, j])