Skip to content

Instantly share code, notes, and snippets.

View deusmachinea's full-sized avatar
🎯
focussing

deus_machinea deusmachinea

🎯
focussing
View GitHub Profile
struct Cow{}
struct Cat{}
trait Animal {
fn signature(&self) -> &'static str;
}
@deusmachinea
deusmachinea / git.migrate
Created January 2, 2020 17:25 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@deusmachinea
deusmachinea / iam-policy-cognito
Created December 11, 2019 14:59
Policy to limit authorised cognito users to a folder in s3 bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::bucketname"
Vagrant.configure(2) do |config|
config.vm.define "sawtoothprocessor" do |sawtoothprocessor|
sawtoothprocessor.vm.box = "ubuntu/bionic64"
sawtoothprocessor.vm.hostname = "sawtoothprocessor"
sawtoothprocessor.vm.network "private_network", type: "dhcp"
sawtoothprocessor.vm.synced_folder "/home/kaali/Programs/SawtoothProcessor", "/home/vagrant/SawtoothProcessor"
sawtoothprocessor.disksize.size = '15GB'
sawtoothprocessor.vm.provider "virtualbox" do |box|
@deusmachinea
deusmachinea / coroutines.py
Last active July 13, 2019 09:34
When coroutines should be wrapped in tasks?
import asyncio
"""
between create_task and ensure_future
Another important difference is that in addition to accepting coroutines,
ensure_future also accepts any awaitable object; create_task on the other hand just accepts coroutines.
"""
async def msg(text):
await asyncio.sleep(0.1)
print(text)
@deusmachinea
deusmachinea / blocking_to_async.py
Last active July 13, 2019 09:41
Convert blocking synchronous python code into asynchronous asyncio
import asyncio
import time
import functools
import concurrent.futures
##your blocking synchronous function
def print_counter(counter):
time.sleep(1)
print (f"THis is the counter {counter}")
return
from mnemonic import mnemonic as mnemoniclib
from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
import os
def generate_entropy():
strength_bits = 128
entropy = os.urandom(strength_bits // 8)
#!/bin/bash
# First we need to get the modeline string for xrandr
# Luckily, the tool "gtf" will help you calculate it.
# All you have to do is to pass the resolution & the-
# refresh-rate as the command parameters:
gtf 2880 1620 60
# In this case, the horizontal resolution is 1920px the
# vertical resolution is 1080px & refresh-rate is 60Hz.
@deusmachinea
deusmachinea / remove_all_tags.py
Created July 1, 2019 21:28
To remove all html tags , css and JS tags from a string.
from lxml.html.clean import Cleaner
import lxml
def get_clean_html(self, html_text, text_only=True):
"""
THis will remove all html tags but still will insert spaces
in the cleaned string
"""
etree = lxml.html.document_fromstring(html_text)
//Traversal Interfcae to implement
type Traversal interface {
Initialize() []int
PrintTraversal(stack []*Tree, res []int, visited map[int]bool) []int
util(stack []*Tree, res []int, visited map[int]bool) ([]int, []*Tree)
}
type defImplement struct {
}