Skip to content

Instantly share code, notes, and snippets.

@canwe
canwe / tsp.py
Created September 28, 2019 15:01 — forked from turbofart/tsp.py
Applying a genetic algorithm to the travelling salesman problem
#!/usr/bin/env python
"""
This Python code is based on Java code by Lee Jacobson found in an article
entitled "Applying a genetic algorithm to the travelling salesman problem"
that can be found at: http://goo.gl/cJEY1
"""
import math
import random
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# how to obtain google translation api key: https://cloud.google.com/translate/docs/quickstart-client-libraries-v3#client-libraries-install-python
import json
import glob
import os
import re
import requests
@canwe
canwe / rsa.py
Created June 10, 2019 16:18 — forked from tylerl/rsa.py
RSA Explained in Python
#!/usr/bin/env python
# This example demonstrates RSA public-key cryptography in an
# easy-to-follow manner. It works on integers alone, and uses much smaller numbers
# for the sake of clarity.
#####################################################################
# First we pick our primes. These will determine our keys.
#####################################################################
@canwe
canwe / gist:a88ca835dda396c874df7e9195c75c0b
Created May 31, 2019 13:07 — forked from jmesnil/gist:3187135
Compare Java and data serialization
package org.jboss.as.test.smoke.jms.objectmessage;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.UUID;
public class Main {
@canwe
canwe / ManagerUI.java
Created May 28, 2019 13:07 — forked from joelbinn/ManagerUI.java
Get CDI bean from bean manager.
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.naming.InitialContext;
import javax.naming.NamingException;
:
private static BeanManager getBeanManager() {
try {
InitialContext initialContext = new InitialContext();
return (BeanManager) initialContext.lookup("java:comp/BeanManager");
@canwe
canwe / curl.md
Created March 28, 2019 06:44 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@canwe
canwe / gist:1c678d8ad4cf51b1c3115be1bdd34045
Created March 1, 2019 20:32 — forked from density215/gist:3146297
Django on OSX Snow Leopard with virtualenv
# you can make a text file of request times (in ms, one number per line) and import it here, or you can use a probability distribution to simulate request times (see below where setting req_durations_in_ms)
# rq = read.table("~/Downloads/request_times.txt", header=FALSE)$V1
# argument notes:
# parallel_router_count is only relevant if router_mode is set to "intelligent"
# choice_of_two, power_of_two, and unicorn_workers_per_dyno are only relevant if router_mode is set to "naive"
# you can only select one of choice_of_two, power_of_two, and unicorn_workers_per_dyno
run_simulation = function(router_mode = "naive",
reqs_per_minute = 9000,
@canwe
canwe / learn_crypto.txt
Created August 24, 2018 09:13 — forked from abderraouf-adjal/learn_crypto.txt
Learn crypto links
أساسيات التشفير - رواق
http://www.rwaq.org/courses/introduction-to-encryption
Applied Cryptography - UDACITY
https://www.udacity.com/course/cs387
Theory and Practice of Cryptography - GoogleTechTalks
http://youtu.be/IzVCrSrZIX8
CISSP Training - Cryptography - The Geek Academy
# -*- coding:utf-8 -*-
import sys
import numpy.random
import itertools
class GostCrypt(object):
def __init__(self, key, sbox):
assert self._bit_length(key) <= 256
self._key = None