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 <cstdlib> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include "rational_number.h" | |
#define GIVEN_NUMBERS 4 | |
#define DEFAULT_TARGET 24 | |
using namespace std; |
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
"""A simple example of multiprocessing for a CPU-bound task in Python. | |
Adapted from https://www.toptal.com/python/beginners-guide-to-concurrency-and-parallelism-in-python | |
""" | |
from multiprocessing.pool import Pool | |
import time | |
def fib(n): | |
"""A (contrived) example of a CPU-intensive function that you may want to parallelize.""" |
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
"""A simple implementation of a recursive-descent parser for a language of boolean expressions.""" | |
import readline | |
def eval_str(expr): | |
"""Evaluate a boolean expression with the symbols '0', '1', '|', '&', '(' and ')'. All binary | |
operators must be wrapped in parentheses, even when it would be unambiguous to omit them. | |
""" | |
tokens = tokenize(expr) | |
ast = match_expr(tokens) |
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
#!/usr/bin/env python3 | |
"""Generate random strings from the template at xkcd.com/1930/.""" | |
import random | |
import re | |
from collections import namedtuple | |
XKCD_STRING = '''\ | |
Did you know that (the (fall|spring) equinox|the (summer|winter) solstice|the (Summer|Winter) | |
Olympics|the (earliest|latest) (sunrise|sunset)|Daylight (Saving|Savings) Time|leap (day|year)| |
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 <errno.h> | |
#include <iconv.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void print_bytes(const char* prefix, const char* str, size_t len); | |
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 cryptography.hazmat.backends import default_backend | |
from cryptography.hazmat.primitives import hashes | |
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey | |
from cryptography.hazmat.primitives.kdf.hkdf import HKDF | |
from cryptography.hazmat.primitives.padding import PKCS7 | |
from cryptography.hazmat.primitives.ciphers import Cipher, modes, algorithms | |
import os |
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 mylib, testhelper as th | |
>>> fibonacci = th.register(mylib.fibonacci) | |
>>> fib(12) | |
144 | |
[testhelper] Is this the expected result (y[es]/n[o]/c[ancel])? y | |
>>> fib(-1) | |
Traceback (most recent call last): | |
... | |
ValueError | |
[testhelper] Is this the expected result (y[es]/n[o]/c[ancel])? y |
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 lombok.Data; | |
public class Enclosing { | |
@Data | |
public static class Inner { | |
private String value; | |
} | |
public static void main(String[] args) { | |
Inner inner1 = new Inner(); |
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
""" | |
DEPRECATED: see my bookmarks_from_sql.py gist. | |
A short script to parse bookmark exports from Firefox so they can be | |
manipulated with Python. | |
Author: Ian Fisher ([email protected]) | |
Version: November 2018 | |
""" | |
from collections import namedtuple |
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
"""Small but complete example of a Pratt recursive-descent parser for the following | |
grammar: | |
start := expr | |
expr := expr op expr | call | LPAREN expr RPAREN | MINUS expr | INT | SYMBOL | |
call := SYMBOL LPAREN arglist? RPAREN | |
op := PLUS | ASTERISK | MINUS | SLASH | |
arglist := (expr COMMA)* expr |
OlderNewer