Skip to content

Instantly share code, notes, and snippets.

View Glyphack's full-sized avatar
🔨
Building Enderpy

Shaygan Hooshyari Glyphack

🔨
Building Enderpy
View GitHub Profile
@Glyphack
Glyphack / redirect.lua
Created December 29, 2023 11:47
Redirect URLs with Hammerspoon
-- Define the Lua table that maps names to URLs
local urlTable = {
john = "https://example.com/john",
alice = "https://example.com/alice",
bob = "https://example.com/bob",
}
-- Register a callback for the custom hammerspoon:// URLs
hs.urlevent.bind("example", function(eventName, params, senderPID)
local event = eventName -- The event name is the host in hammerspoon://host
@Glyphack
Glyphack / print_symbol_table.py
Created August 18, 2023 19:22
Script to print symbol table of a python code
import symtable
def print_symbol_table_info(symbol_table: symtable.SymbolTable, indent=0):
# Print the information of the current symbol table
print(" " * indent + f"Symbol Table: {symbol_table.get_name()}")
print(" " * (indent + 2) + f"Type: {symbol_table.get_type()}")
print(" " * (indent + 2) + f"Identifier: {symbol_table.get_id()}")
print(" " * (indent + 2) + f"First Line Number: {symbol_table.get_lineno()}")
# print(" " * (indent + 2) + f"Is Optimized: {symbol_table.is_optimized()}")
# print(" " * (indent + 2) + f"Is Nested: {symbol_table.is_nested()}")
@Glyphack
Glyphack / game-of-life.go
Created May 29, 2023 14:59
Game of life in go
package main
import "fmt"
type Cell struct {
x int
y int
state int
}
@Glyphack
Glyphack / channels_blocking.go
Created March 11, 2023 15:22
Golang: Wait group, channels, blocking operation
package main
import (
"fmt"
"sync"
)
func main() {
ch := make(chan int)
wg := sync.WaitGroup{}
@Glyphack
Glyphack / avro_schema_to_swagger.py
Last active September 1, 2022 10:39
Generate openapi swagger object definition form avro schema
"""
Convert Avro schema files to swagger object definitions.
"""
import argparse
import json
from dataclasses import dataclass
from typing import Dict, List
parser = argparse.ArgumentParser(
description="Convert avro schema file to swagger object definition"
@Glyphack
Glyphack / 2fa.py
Created August 8, 2020 18:11
a script to copy steam 2fa code into clipboard
from steampy import guard
import pyperclip
pyperclip.copy(guard.generate_one_time_code("shared secret"))
@Glyphack
Glyphack / test_schema.py
Created August 23, 2019 14:36
graphql test case
from django.contrib.auth import get_user_model
from utils.test_utils import APITestCase
from .graphql_requests import (
CREATE_LINK_MUTATION
)
class LinkTestCase(APITestCase):
def setUp(self):
@Glyphack
Glyphack / graphql_test_utils.py
Created August 23, 2019 14:18
functions to test graphql api with python
from django.contrib.auth.models import AnonymousUser
from django.test import RequestFactory
from snapshottest.django import TestCase
from graphene.test import Client
from hackernews.schema import schema
class APITestCase(TestCase):
def setUp(self):
@Glyphack
Glyphack / time_sort.py
Last active April 25, 2019 11:48
Implementing sorting with async.sleep
import asyncio
import time
import random
async def task(i):
await asyncio.sleep(i* 0.01)
print(i)
async def main():
a = [random.randint(0, 100) for _ in range(0, 100)]
coroutines = list()
@Glyphack
Glyphack / auto_comment_bot
Created January 20, 2019 11:23
auto instagram comment bot
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from time import sleep
from ast import literal_eval
import random
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import WebDriverException