Skip to content

Instantly share code, notes, and snippets.

View 46bit's full-sized avatar
🏳️‍🌈

Miki Mokrysz 46bit

🏳️‍🌈
View GitHub Profile
@46bit
46bit / test.hs
Last active August 29, 2015 14:02
Tiny demo of my Haskell Turing Machine (https://gist.github.com/46bit/46fba4b32db68a5f47c9)
import TM
import Data.Maybe
main :: IO ()
main = print . TM.prettyTM . TM.executeTM $
TM.createTM "bbc" [(0, 'a', 'b', TM.Idle, 1), (1, 'b', 'c', TM.Right, 1)]
@46bit
46bit / tm.hs
Last active August 29, 2015 14:02
Turing Machine in Haskell.
module TM (
State,
Symbol,
Direction(..),
Transition,
ZipTape,
TM,
prettyTransition,
prettyZipTape,
prettyTM,
@46bit
46bit / bn_lib.c
Created November 17, 2014 22:47
An extract from OpenSSL crypto/bn/bn_lib.c. BN_bn2bin is used to extract binary data from bignums. I think?
int BN_bn2bin(const BIGNUM *a, unsigned char *to)
{
int n,i;
BN_ULONG l;
bn_check_top(a);
n=i=BN_num_bytes(a);
while (i--)
{
l=a->d[i/BN_BYTES];
@46bit
46bit / alphac.py
Last active August 29, 2015 14:13
ALPHAC text encrypter that I'm attacking for fun, reimplemented cleanly in Python. Source: http://www.myersdaily.org/joseph/javascript/alphac.html.
from random import randint
# ALPHAC encryption method
# From http://www.myersdaily.org/joseph/javascript/alphac.html
# This a much cleaner Python reimplementation for Cryptanalysis.
class Alphac:
c64 = list("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
# s = input string (only characters in c64)
# k = key string (only characters in c64)
@shinzui
shinzui / connection_fix.rb
Created December 6, 2009 06:18 — forked from defunkt/connection_fix.rb
MySQL automatic reconnect
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@arirusso
arirusso / expression_timer.rb
Created April 30, 2012 01:51
Ruby methods for protecting against timing attacks
#!/usr/bin/env ruby
#
# Ruby methods for protecting against timing attacks
#
module ExpressionTimer
# a shortcut to ExpressionTimer.send that passes in the object for which this module
# was included
#
@46bit
46bit / b_upload.rb
Created November 8, 2012 06:28
My shell file uploader. SCPs files but allows for deleting afterwards, randomising names, etc. Ideal for screenshot uploading.
#!/usr/bin/env ruby
require 'optparse'
require 'digest/md5'
require 'net/scp'
require "fileutils"
options = { }
optparse = OptionParser.new do |opts|
opts.banner = "Usage: b_upload [-p|--preserve|-d|--delete-local] file"
@46bit
46bit / lfsr.py
Created November 2, 2016 00:27
Tests need Python 3.4 or greater (for `unittest.TestCase.subTest`).
import operator
import functools
import unittest
import random
class LFSR():
def __init__(self, width, taps=None, seed=1):
if width < 1:
raise ValueError("Requested LFSR width < 1.")
@robey
robey / simplified-future.md
Last active April 10, 2017 20:00
Changing the shape of rust Future & Stream

Changing the shape of rust Future & Stream

On the tokio chat, @carllerche suggested that one way to simplify the "errors on streams" problem (rust-lang/futures-rs#206) would be to remove the error alternative from Future & Stream. This idea stuck with me, and I want to sketch out a possible alternative, to see how it would look.

Currently

  • Future<Item, Error>: A future resolves to either an item or an error type, exactly like an async version of Result.
    • poll() -> Poll<Item, Error>: not ready, or an item, or an error
  • Stream<Item, Error>: A stream emits elements that are each either an item or error, exactly like an async iterable of Result.
    • poll() -> Poll<Option<Item>, Error>: not ready, or the end of the stream (Ready(None)), or an item, or an error
@chrishanretty
chrishanretty / conswing.R
Last active April 24, 2017 20:45
Analysis of swings in Conservative and Labour-held seats, BES data
library(foreign) ## for data import
library(dplyr) ## for chaining ops together
library(ggplot2) ## for plotting
library(reshape2) ## for reshaping
library(hrbrthemes) ## for pretty pictures
library(survey) ## for... uh, survey data
party.colours <- c("#0087DC","#D50000","#FDBB30","#FFFF00","#008142","#99CC33","#70147A","#DDDDDD")
bes <- read.spss("~/Dropbox/2017-forecasting/data/individual/BES2015_W10_Panel_v0.3.sav")