Skip to content

Instantly share code, notes, and snippets.

@creasyw
creasyw / spacemacs-keybindings
Created May 13, 2018 03:13 — forked from adham90/spacemacs-keybindings
spacemacs keybindings that i need to learn
SPC s c remove highlight
**** Files manipulations key bindings
Files manipulation commands (start with ~f~):
| Key Binding | Description |
|-------------+----------------------------------------------------------------|
| ~SPC f c~ | copy current file to a different location |
| ~SPC f C d~ | convert file from unix to dos encoding |
| ~SPC f C u~ | convert file from dos to unix encoding |
@creasyw
creasyw / apply_df_by_multiprocessing.py
Created September 2, 2016 23:53 — forked from yong27/apply_df_by_multiprocessing.py
pandas DataFrame apply multiprocessing
import multiprocessing
import pandas as pd
import numpy as np
def _apply_df(args):
df, func, kwargs = args
return df.apply(func, **kwargs)
def apply_by_multiprocessing(df, func, **kwargs):
workers = kwargs.pop('workers')
@creasyw
creasyw / longestPalindrome.py
Created February 23, 2015 21:47
Manacher's Algorithm
def longestPalindrome(self, s):
pt = 0
temp = s
while pt < len(temp):
temp = temp[:pt]+"#"+temp[pt:]
pt += 2
temp = temp + "#"
# the up-to-date longest center of palindrome
center = 0
# r is for range from the current longest center of palindrome
import numpy as np
import re, sys
from collections import defaultdict
def build_board(filename):
board = np.zeros((9, 9))
f = open(filename, 'r')
for i in range(9):
board[i] = [int(k) for k in re.findall(r'\d', f.readline())]
return board
@creasyw
creasyw / fibonacci.py
Last active August 29, 2015 14:13
Fibonacci Number
import numpy as np
# Recursion
fib = lambda n: fib(n-1)+fib(n-2) if n > 2 else 1
# Memoization
def fib_memo(n):
register = {0: 0, 1: 1}
def helper(count):
if count in register: