Skip to content

Instantly share code, notes, and snippets.

View domluna's full-sized avatar
🐺
howling time

Dominique Luna domluna

🐺
howling time
View GitHub Profile
@domluna
domluna / blah.txt
Created July 16, 2014 20:49
2 files > 1 file
blahhing away
@domluna
domluna / ssh.go
Created July 18, 2014 03:32
Playing around with ssh clients in Go
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net"
"os/user"
"time"
@domluna
domluna / resize_linux.txt
Created August 24, 2014 20:45
How to resize linux partitions without cd/usb
Resize Linux partition without any disks/cds/usb things!
Works on Ubuntu 14.04, probably fine on others
1.
sudo losetup /dev/loop0
2. /path/to/file is found with 1., xxx is the number of MiBs to allocate, note: 1MiB ~ 1MB
sudo dd if=/dev/zero bs=1MiB of=/path/to/file conv=notrunc oflag=append count=xxx
@domluna
domluna / pointer.rs
Created September 13, 2014 22:51
Rust pointers, boxing/heap
// Pretend this is an actual big struct in which it would be
// expensive to copy by value.
struct BigStruct {
one: int,
two: int,
// etc
one_hundred: int,
}
// An antipattern would be for the return type to be
@domluna
domluna / macro.rs
Created September 13, 2014 23:02
Example of a macro in rust
#![feature(macro_rules)]
macro_rules! loop_x {
($e: expr) => {
// $e will not interact with this 'x
// refers to the 'x in the outside loop
'x: loop {
println!("Hello!");
$e
}
@domluna
domluna / pre-commit_example
Created September 13, 2014 23:03
Example of pre-commit for git, in this case it's making sure go files are fmted
#!/bin/sh
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# git gofmt pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#
@domluna
domluna / matching.py
Last active August 29, 2015 14:07
Matching parens
def match(s, pairs):
stack = []
closers = set(pairs.values())
for c in s:
if c in pairs:
stack.append(pairs[c])
elif c in closers:
# we can end early if either is true
if not stack or c != stack.pop():
@domluna
domluna / lcs.py
Created October 18, 2014 05:12
Longest common substring between two strings
def longest_common_substring(s1, s2):
"""
lcs[i,j] = if match lcs[i-1, j-1] + 1
lcs[i,j] = if not match 0
"""
m = len(s1)
n = len(s2)
# Hash table not be more memory efficient. Here we have n*m
# entries guaranteed. In a hash table all entries that are 0
@domluna
domluna / spiral.py
Created October 18, 2014 18:04
Matrix spiral print
def spiral(M):
"""
Given a matrix M (mxn) print out the elements in spiral order
Ex:
30 42 30 55 31
21 30 60 24 38
11 22 33 44 55
@domluna
domluna / 3_convnet.py
Last active September 6, 2015 21:25
convnet with cgt
from __future__ import print_function, absolute_import
import cgt
from cgt import nn
from cgt.distributions import categorical
import numpy as np
from load import load_mnist
import time
epochs = 10
batch_size = 128