This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
SWIPE = 0.1 # Percentage of times user unlocks when he sees rewards. | |
# Sample randomly from the seconds space of a day, N times. | |
# Simulates user on/off actions | |
def sample_ticks(n): | |
wakeups = [random.randrange(1, 3600*24 + 1) for _ in range(n)] | |
wakeups.sort() | |
return wakeups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from billi.redis_utils import get_redis, KEY_DAILY_ACTIVE_USER | |
from django.contrib.auth.models import User | |
from billi.utils import from_string_to_utc, utcnow, from_utc_to_local | |
from dateutil.rrule import rrule, DAILY | |
import binascii | |
from billi.settings import BILLI_DEFAULT_TIMEZONE_OFFSET, BILLI_DEFAULT_TIMEZONE | |
import logging | |
from datetime import timedelta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def compute_mean(alist): | |
sum_ = 0 | |
for idx in range(len(alist)): | |
sum_ = sum_ + alist[idx] | |
return sum_/float(len(alist)) | |
def compute_median(alist): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
def fibonacci_while_loop(n): | |
#compute the n-th fibonacci number. n > 2 | |
count = 2 | |
first, last = 1, 1 | |
while count < n: | |
first, last = last, first + last | |
count += 1 | |
return last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Nate' | |
import requests | |
import datetime | |
import json | |
import re | |
import sys | |
channel_mapping = { | |
'new-adn-campaign-jp': 'C0CV6C3JP', | |
'new-adn-campaign-tw': 'C0CV6C3RR', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
char board[12][6]; | |
int processed[12][6]; | |
char dir[4][2] = { | |
{-1,0}, //up | |
{1,0}, //down | |
{0,1}, //right | |
{0,-1}, //left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import random | |
from collections import defaultdict | |
def weighted_choice(choices, n): | |
""" | |
n개의 에드네트워크 정보를 픽한다. 단 이미 선택된 에드네트워크는 고려 대상에서 제외된다 (sample without replacement). | |
힙 자료구조를 이용한다. O(nlogn) | |
:param choices: 에드네트워크 초이스 정보가 담긴 리스트. 각 초이스정보는 딕셔너리. 딕셔너리의 키는 weight, adnetwork id, api key. | |
:param n: 픽 갯수. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func throw_dice (arr_weights) { | |
W <- sum(arr_weights) | |
T <- RANDOM(0, W) // sample uniformly from [0, W) | |
cumsum <- 0 | |
FOR i in 0..n-1, DO { | |
IF T-cumsum <= arr_weigths[i], THEN | |
RETURN arr_weights[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variant = [[1,2,4,5,6],[7,8,10,11,12],[13,14,16,17,18],[19,20,22,23,24],[25,26,28,29,30]] | |
for a in variant: | |
row = a | |
next = row[1] | |
for i in row: | |
if next-i == 1: | |
if next == row[1]: | |
next = row[2] | |
elif next == row[2]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variant = [[1,2,4,5,6],[7,8,10,11,12],[13,14,16,17,18],[19,20,22,23,24],[25,26,28,29,30]] | |
for a in variant: | |
row = a | |
next = row[1] | |
for i in row: | |
if next-i == 1: | |
if next == row[1]: | |
next = row[2] | |
elif next == row[2]: |
OlderNewer