This file contains hidden or 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
| serve_file(Response, File) -> | |
| case file:open(File, [raw, binary]) of | |
| {ok, IoDevice} -> | |
| %% Set ChunkSize to an optimal value | |
| ChunkSize = 1024, | |
| Stream = iodevice_stream(IoDevice, ChunkSize), | |
| Response1 = setelement(4, Response, Stream), | |
| file:close(IoDevice), | |
| Response1; | |
| _ -> |
This file contains hidden or 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
| # a heavy int is one where the average of the digits is greater than 7 | |
| # eg: 8678 is heavy because (8 + 6 + 7 + 8) / 4 = 7.25 | |
| # 8677 is not heavy because ( 8 + 6 + 7 + 7) / 4 = 7 | |
| def is_heavy(my_number, heaviness=7): | |
| # map each digit to a float and divide by the length | |
| digits = str(my_number) | |
| return sum(map(float, digits)) / len(digits) > heaviness |
This file contains hidden or 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 time | |
| class TimedOperation(object): | |
| "Describes a single operation with timing information" | |
| __slots__ = ('description', '_cpustart', '_cpuend', '_wallstart', '_wallend') | |
| def __init__(self, description): | |
| self.description = description | |
| self._cpustart = time.clock() | |
| self._cpuend = None |
This file contains hidden or 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 sys | |
| class Foo(object): | |
| def __init__(self, value): | |
| self._value = value | |
| def __long__(self): | |
| return long(self._value) | |
This file contains hidden or 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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import os | |
| import sys | |
| # Fix import paths | |
| base_dir = os.path.join(os.path.dirname(os.path.realpath(__file__))) | |
| sys.path.append(base_dir) | |
| import pika |
This file contains hidden or 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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import os | |
| import sys | |
| # Fix import paths | |
| base_dir = os.path.join(os.path.dirname(os.path.realpath(__file__))) | |
| sys.path.append(base_dir) | |
| import pika |
This file contains hidden or 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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Note: Requires https://github.com/skarab/pika/tree/rabbitmq-ext | |
| # for RabbitMQ exchange binding extensions | |
| import csv | |
| import getopt | |
| import os | |
| import random | |
| import sys | |
| import time |
This file contains hidden or 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
| % Entry point from Misultin | |
| ws_loop(Ws) -> | |
| WsPid = self(), | |
| {ok, Pid, Uuid} = erlsio_session_sup:start_child(?MODULE, [WsPid]), | |
| % This is OK because the child session process will time out if we | |
| % die before this link. | |
| true = link(Pid), | |
| % First step is to send session ID | |
| Ws:send(erlsio_protocol:encode({text, Uuid})), | |
| ?MODULE:ws_loop_1(#loop_state{ws = Ws, pid = Pid, uuid = Uuid}). |
This file contains hidden or 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 <stdio.h> | |
| #include <string.h> | |
| #include <openssl/blowfish.h> | |
| #include <openssl/evp.h> | |
| int main(int argv, const char **argc) | |
| { | |
| const unsigned char keytext[] = "key"; | |
| const unsigned char plaintext[] = "this is plaintext"; | |
| const unsigned char ivec[] = "12345678"; |
This file contains hidden or 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
| open_connection_link(Params) -> | |
| process_flag(trap_exit, true), | |
| {ok, Conn} = amqp_connection:start(network, Params), | |
| link(Conn), | |
| receive | |
| {'EXIT', Conn, Reason} -> | |
| exit(Reason); | |
| {'EXIT', _Pid, Reason} -> | |
| ok = amqp_connection:close(Conn), | |
| exit(Reason) |