Skip to content

Instantly share code, notes, and snippets.

@rainzoo
rainzoo / .emacs
Last active November 28, 2020 08:20
;;(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
;;'(ansi-color-names-vector ["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#ad7fa8" "#8cc4ff" "#eeeeec"])
;;'(custom-enabled-themes (quote (wombat))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
@rainzoo
rainzoo / Alice_Vs_VirtualBox.md
Created October 20, 2016 06:53
Alice Vs VirtualBox

Bug

Alice asks VirtualBox to delete a snapshot. Not just any snapshot but one whose child snapshot has a snapshot. VirtualBox deletes the snapshot file, but when she launchs the VM, VirtualBox complains:

Failed to open a session for the virtual machine VMName V2.

Could not open the medium 'C:\Users\Alice\VirtualBox VMs\VMName V2\Snapshots/{snapshot_that_should_have_been_deleted}.vdi'.

VD: error VERR_FILE_NOT_FOUND opening image file 'C:\Users\Alice\VirtualBox VMs\VMName V2\Snapshots/{snapshot_that_should_have_been_deleted}.vdi' (VERR_FILE_NOT_FOUND).
def champ(n):
s = ""
for x in xrange(0,n+1):
s = s + str(x)
return int(s[n])
k = [1, 10, 100, 1000 ,10000, 100000, 1000000]
ans = 1
#either
@rainzoo
rainzoo / uinique_values.py
Created January 26, 2013 16:01
Extract unique combinations of columns (number 1 to 4) in a tab separated file.
with open('sample.txt') as fi:
dct = {}
header = fi.readline()
"""Couldn't figure what this row is for
"""
rec1 = fi.readline()
for line in fi.readlines():
x = line.split()[1:5]
key = ",".join(x)
dct[key] = dct.get(key, 0) + 1
@rainzoo
rainzoo / NumberToWords.scala
Last active December 10, 2015 19:29
Convert numbers to words, numbers up to thousands.
object NumberToWords {
val units = List("one", "two", "three", "four",
"five", "six", "seven", "eight", "nine")
val teens = List("ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
val tens = List("twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety")
def main(args: Array[String]) {
@rainzoo
rainzoo / index.html
Created August 10, 2012 13:51 — forked from mbostock/.block
Circular Layout (Raindrops)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Raindrops</title>
<script type="text/javascript" src="https://github.com/mbostock/d3/raw/v1.4.0/d3.js"></script>
<style type="text/css">
body {
background: #012;
@rainzoo
rainzoo / gist:3116988
Created July 15, 2012 13:47
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@rainzoo
rainzoo / Hello.m
Created July 5, 2012 19:04
Compile and run Objective C program on Ubuntu 11.04
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@autoreleasepool {
NSLog(@"Hello World");
}
}
"""Find the largest palindrome made from the product of two 3-digit numbers."""
from itertools import combinations as cnr
print max([ x*y for (x,y) in cnr(range(100,999),2) if str(x*y) == str(x*y)[::-1]])
"""Closing the loop
http://code.google.com/codejam/contest/dashboard?c=837485#s=p0
"""
def nmax(l,n):
"""Find sum of n highest numbers from list l
"""
if l and n <= len(l):
temp = l[:]
temp.sort()
temp.reverse()