Skip to content

Instantly share code, notes, and snippets.

View diezguerra's full-sized avatar

Saúl diezguerra

View GitHub Profile
@diezguerra
diezguerra / .vimrc
Created October 8, 2014 01:39
Vimrc 10/7/2014
set nocompatible
filetype off
set shell=bash
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'kien/ctrlp.vim'
Bundle 'alfredodeza/khuno.vim'
Bundle 'tpope/vim-commentary'
Bundle 'tpope/vim-surround'
@diezguerra
diezguerra / rot90_o1.py
Created October 17, 2014 05:31
rot90 O(1) space
import numpy as np
arr = np.arange(1, 26).reshape((5, 5))
arr2 = np.arange(1, 26).reshape((5, 5))
def rot90(arr):
for circle in range(len(arr) // 2):
for item in range(0, len(arr) - 1 - 2 * circle):
int equi ( int[] arr ) {
long left = 0;
long right = 0;
/* sumamos todos a la izquierda */
for(int i : arr) {
left += i;
}
/* vamos comprobando y restando a la izquierda y sumando a la dcha */
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-fugitive'
Bundle 'kevinw/pyflakes'
Bundle 'kevinw/pyflakes-vim'
Bundle 'nvie/vim-flake8'
Bundle 'kien/ctrlp.vim'
@diezguerra
diezguerra / watching.rb
Last active October 20, 2015 17:25
Cagers
# 23 8-18 * * 1-5 curl -L tenwar.com/watching | ruby >/dev/null 2>&1
require('Open3')
if rand(1...10) > 9
osa_script = <<'End'
activate application "Safari"
delay 2
@diezguerra
diezguerra / cager.sh
Created October 16, 2014 21:35
Cager
curl "http://www.ardemagazine.com/arde/wp-content/uploads/2014/04/1sNE1eX.jpg" > ~/Downloads/caged.jpg
osascript -e "tell application \"System Events\" to set picture of every desktop to \"~/Downloads/caged.jpg\""
@diezguerra
diezguerra / powpow.clj
Created October 6, 2014 18:28
Implementations of power in Clojure
(defn create-power
"Takes a positive power-of implementation and returns a function that uses
it plus the logic for y==0 and y<0"
[implementation]
(fn [x y]
(cond
(> y 0) (implementation x y)
(< y 0) (/ 1 (implementation x (Math/abs y)))
:else 1)))
@diezguerra
diezguerra / cs_books.md
Created October 20, 2015 17:22
CS books email
@diezguerra
diezguerra / filterdict.py
Last active December 14, 2015 00:39
How to filter dicts in python, the right way.
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <rawcell>
# How to filter Python dictionaries, the right way.
#
# Expected output:
# Original list lookup => 100 loops, best of 3: 9.82 ms per loop
# Dict trick lookup => 1000 loops, best of 3: 315 us per loop
@diezguerra
diezguerra / slice_upsert.py
Last active December 15, 2015 18:29
Python Slice Upsert
a_range = range(12)
a_range[-2:] = range(10,20)
assert a_range == range(20)
a_range[10:11] = range(10)[::-1]
a_range[20:] = []
assert a_range == range(10) + range(10)[::-1]
keywords = "apple, pear, banana, lemon and orange"
keywords = keywords.split(', ')