Skip to content

Instantly share code, notes, and snippets.

View evanthebouncy's full-sized avatar
💯
每人都发小红花

evanthebouncy

💯
每人都发小红花
View GitHub Profile
@evanthebouncy
evanthebouncy / gist:9613715
Created March 18, 2014 04:45
postgresql shmall setting error
root@production:~# sudo /etc/init.d/postgresql start
* Starting PostgreSQL 9.1 database server * The PostgreSQL server failed to start. Please check the log output:
2014-03-18 00:39:51 EDT FATAL: could not create shared memory segment: Cannot allocate memory
2014-03-18 00:39:51 EDT DETAIL: Failed system call was shmget(key=5432001, size=430235648, 03600).
2014-03-18 00:39:51 EDT HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. You can either reduce the request size or reconfigure the kernel with larger SHMALL. To reduce the request size (currently 430235648 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
The PostgreSQL documentation contains more information about sha
@evanthebouncy
evanthebouncy / is_it_parrot?
Created June 18, 2014 21:54
A simple animal game
# An interactive game where the computer can learn to recognize
# more animals!
# Not sure if this is best practice for clarity, but i kept the
# data structure more like data rather than objects with methods
# so the recursion looks cleaner.
# an animal, like a dog or a cat
class Animal:
def __init__(self, animal):
# you can copy/paste the code to here and run it in browser
# http://www.tutorialspoint.com/execute_julia_online.php
# a simple sigmoid shrink function that wraps x to a range between 0 and 1
shrink_fun(x) = 1 / (1 + e^-x)
# a random function generator,
# it makes a function that maps x to a random point between 0 and 1
function gen_fun()
n = -1.0 + 2*rand() # a random number between -1 and 1
@evanthebouncy
evanthebouncy / rational approximation
Created July 10, 2015 02:03
rational approximation
# rational approximation, approximate a ratio with a rational number n / d
function rational_approx(ratio::Float64, tol::Float64)
# given a list of values for a continued fraction
# reconstruct as a simple fraction n / d
function re_construct(fract_list)
rev_list = reverse(fract_list)
n = rev_list[1]
d = 1
for x in rev_list[2:end]
new_n = n * x + d
@evanthebouncy
evanthebouncy / try_birnn.py
Created December 5, 2015 10:53
trying to understand bidirectional rnn
batch_size = 1
input_size = 2
num_units = 3
input_length = 8
sess = tf.Session()
with tf.variable_scope("root", initializer=tf.constant_initializer(0.5)) as scope:
import tensorflow as tf
import numpy as np
if __name__ == '__main__':
np.random.seed(1)
# the size of the hidden state for the lstm (notice the lstm uses 2x of this amount so actually lstm will have state of size 2)
size = 1
# 2 different sequences total
batch_size= 2
# the maximum steps for both sequences is 10
=======
def oddTuples (x0 ):
x1 =()
for x2 in range (len (x0 ))
if x2 %2==0:
x1 =x1 +x0 [x2 ]
return x1
def oddTuples (x0 ):
x1 =()
=========== put this in timeout.py ==============
from functools import wraps
import errno
import os
import signal
class TimeoutError(Exception):
pass
@evanthebouncy
evanthebouncy / wont_die.py
Created April 15, 2016 18:03
python shit that won't terminate with ctrl-C
def f(x):
while x == x:
if 4 == 3:
x = 3
print f([1,2,3,4,5])
# how much exp if I catch 2 pidgeys and 4 ratatas?
# here 2 pidgey is expressed as (2, 12) where 2 is number of pidgey
# and 12 is how many candy it takes for a pidgey to evolve
# the same goes to ratata, 4 ratatas, and a ratata takes 25 candies
caught = [(1, 400)]
# are you using egg? True or False
lucky_egg = False