Skip to content

Instantly share code, notes, and snippets.

View hashlash's full-sized avatar

hashlash

View GitHub Profile
@hashlash
hashlash / README.md
Last active May 29, 2020 08:19
A Tour of Go Exercise: rot13Reader https://tour.golang.org/methods/23

Some simple points that I think this code looks great:

  • Doesn't need any additional function(s)

  • Concise if case error handling, instead of:

    ...
    if err != nil {

return nil, err

@hashlash
hashlash / battleships.py
Last active April 27, 2020 16:02
Battleship puzzle solver
from itertools import combinations, product
from pysat.solvers import Minisat22
from sympy.core.symbol import Symbol
from sympy.logic.boolalg import And, Equivalent, Not, Or, to_cnf
def simplify_op(op, args):
simplified = op(*args)
if isinstance(simplified, op):
@hashlash
hashlash / gist:e6620513b541a3a8c441272c39918bfe
Created April 11, 2020 09:41
Run command with unlimited sudo session time
#!/bin/sh
(while true; do sudo -v; sleep 60; done)&
job_pid=$!
echo $job_pid
cleanup(){
kill $job_pid
}
@hashlash
hashlash / gsoc-django-secret-manager.md
Last active August 31, 2021 04:50
Django GSOC 2020 Proposal: Secrets Manager
🔥 Creating kvm2 VM (CPUs=2, Memory=2200MB, Disk=20000MB) ...
I0324 14:25:28.958816 22940 main.go:110] libmachine: Found binary path at /home/hashlash/.minikube/bin/docker-machine-driver-kvm2
I0324 14:25:28.958860 22940 main.go:110] libmachine: Launching plugin server for driver kvm2
I0324 14:25:28.969823 22940 main.go:110] libmachine: Plugin server listening at address 127.0.0.1:44705
I0324 14:25:29.028042 22940 main.go:110] libmachine: () Calling .GetVersion
I0324 14:25:29.029004 22940 main.go:110] libmachine: Using API Version 1
I0324 14:25:29.029044 22940 main.go:110] libmachine: () Calling .SetConfigRaw
I0324 14:25:29.029644 22940 main.go:110] libmachine: () Calling .GetMachineName
I0324 14:25:29.030153 22940 main.go:110] libmachine: (kvm) Calling .GetMachineName
I0324 14:25:29.030396 22940 main.go:110] libmachine: (kvm) Calling .DriverName
c := make(chan Return)
ch.NotifyReturn(c)
for r := range(c) {
fmt.Println(r)
}
from sklearn.naive_bayes import _BaseNB
class MultiNB(_BaseNB):
def __init__(self, models_dict):
self.models_dict = models_dict
def fit(self, X, y, **kwargs):
for column, model in self.models_dict.items():
model.fit(X[:, column], y, **kwargs)

Problem statement:

There are N kind of stamps with different prices, denoted by pi as price for i-th stamp. Prove that every amount of postage of x cents or more can be formed using just the stamps above (with price pi for each stamp).

Mathematically we can define:

x = c1.p1 + c2.p2 + ... + cN.pN

with ci is the number of i-th stamp with price pi to form postage of x cents.

@classonlymethod
def as_view(cls, **initkwargs):
"""Main entry point for a request-response process."""
for key in initkwargs:
if key in cls.http_method_names:
raise TypeError("You tried to pass in the %s method name as a "
"keyword argument to %s(). Don't do that."
% (key, cls.__name__))
if not hasattr(cls, key):
raise TypeError("%s() received an invalid keyword %r. as_view "
# rest_framework.generics
class RetrieveUpdateDestroyAPIView(mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
GenericAPIView):
"""
Concrete view for retrieving, updating or deleting a model instance.
"""
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)