Skip to content

Instantly share code, notes, and snippets.

@Se7soz
Se7soz / prob122.cpp
Created February 4, 2014 16:14
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
void insert(tree* root, tree* node) {
if(node == NULL) return;
tree* tmp = root;
while(true) {
if(tmp->d <= node->d) {
if(tmp->rt)
tmp = tmp->rt;
@cleure
cleure / serialize-struct.c
Created February 4, 2014 16:55
A simple example of how to serialize a struct to a file, and load it back into a different struct.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <memory.h>
#include <string.h>
/**
* A simple example of how to serialize a struct to a file, and load it
* back into a different struct.
*
var costMagnitudeRoll = ~~(Math.random() * 100);
if (costMagnitudeRoll < 70) {
cost = Math.random() * 30;
}
else if (costMagnitudeRoll < 90) {
cost = Math.random() * 70 + 30;
}
else if (costMagnitudeRoll < 99) {
cost = Math.random() * 400 + 100;
@Se7soz
Se7soz / prob134.cpp
Created February 4, 2014 16:55
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
struct entry {
int val;
int i, j;
entry(int val, int i, int j) {
this->val = val;
this->i = i;
this->j = j;
}
};
@sqeezy
sqeezy / gist:8806746
Created February 4, 2014 16:11
Compute the determinant of a matrix.
/// <summary>
/// Duplicates a ComplexMatrix without one columns and one row
/// </summary>
/// <param name="matrix"></param>
/// <param name="column"></param>
/// <param name="row"></param>
/// <returns></returns>
private Matrix make_matrix(Matrix matrix, int column)
{
Matrix new_matrix = new Matrix(matrix.Rows - 1, matrix.Columns - 1);
@Se7soz
Se7soz / prob133.cpp
Last active August 29, 2015 13:56
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
#include <iostream>
#include <climits>
#include <cstring>
#include <cmath>
using namespace std;
struct node {
int val;
node* nxt;
node(int val) {
from random import randint
board = [] # makes blank board list
for x in range(5):
board.append(["O"] * 5) # Appends O,O,O,O,O to board[0 through 4]
def print_board(board):
for row in board:
@Battleroid
Battleroid / flashcache
Last active August 29, 2015 13:56
Flashcache init. Using SSD (/dev/sdb) for caching. $local_fs seems to fix startup issue.
#!/bin/sh
# Start or stop Flashcache
### BEGIN INIT INFO
# Provides: flashcache
# Required-Start: $local_fs
# Required-Stop: $remote_fs $network pvedaemon
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
import random
import json
places = []
for x in range(1000): # your choice here
places.append({
"name": "place %d" % x,
"lat": random.randint(-80, 80) + random.random(),
"lon": random.randint(-180, 180) + random.random(),
@kjessup
kjessup / formatted_decimal.lasso
Created April 3, 2014 20:01
This object attempts to work like a decimal, but is able to store its formatting flags, much in the manner of LP8.
define formatted_decimal => type {
    data public value::decimal,
        private flags
     
    public onCreate(flags = (:)) => {
        .value = 0.0
        .flags = #flags
    }
    public onCreate(v::decimal, flags = (:)) => {
        .value = #v