Skip to content

Instantly share code, notes, and snippets.

View ragne's full-sized avatar
🦀
...

Edward ragne

🦀
...
View GitHub Profile
@ragne
ragne / mem_alloc_test.c
Last active September 30, 2021 11:51
A basic test that will allocate memory based on passed options and display available memory stats.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "sys/types.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
#include <stdarg.h>
@ragne
ragne / hw2.md
Created July 21, 2021 10:33
hw2

Я вижу, что вопросы есть :)

Итак, что нужно сделать в дз: у вас есть три функции (format_with_fstring, format_with_format, format_with_percent). Все они принимают только один параметр data: Metrics, такой синтаксис это описание входного типа, здесь использован чтобы показать вам, что тип принимаемой переменной это класс Metrics, написанный выше. Это сделано для того, чтобы ваш редактор (если вы используете IDE), мог подсвечивать вам поля класса когда вы пишете, например, data. (и IDE показывает все доступные поля\методы).

Как делать дз? Все что вам нужно сделать - это написать код в трех ф-циях (format_with_fstring, format_with_format, format_with_percent), который будет возвращать форматированную строку. Для примера: format_with_fstring должна вернуть строку, которая отформатирована

HTTP status getter

Write a terminal application in Python 3 to get a random or user-specified picture from https://http.cat/ with following abilities:

  • get a random status or get user-defined status (via command-line flag; random is default)
  • save it locally in temporary directory
  • and open said image in user's browser

Also program should have:

  • Logging of actions, should log WARN by default with cmdline flag to increase level to DEBUG (-v)
  • Linting enabled and passed
{
"title": "CHEAPEST ASPD + FW | Prontera",
"owner": "Thamur",
"location": { "map": "prontera", "x": 136, "y": 234 },
"creation_date": "2020-05-30T20:03:59Z",
"type": "V",
"items": [
{ "item_id": 656, "amount": 85, "price": 1240 },
{ "item_id": 657, "amount": 90, "price": 2385 },
{ "item_id": 601, "amount": 915, "price": 54 }
"io.cert-manager.acme.v1alpha2.ChallengeList": {
"description": "ChallengeList is a list of Challenge",
"required": [
"items"
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
// gr_mem: Vec<String>
let mut char_vec: Vec<*mut c_char> = Vec::new();
for mem in self.gr_mem.into_iter() {
let c_str = CString::new(mem).unwrap();
let cstr_len = c_str.to_bytes_with_nul().len();
let dst = buf.as_mut_ptr().offset(offset as isize) as *mut i8;
std::ptr::copy_nonoverlapping(c_str.as_ptr(), dst , cstr_len);
char_vec.push(dst);
offset += cstr_len;
@ragne
ragne / slim_jre.sh
Created November 11, 2017 13:37
slim jre down
#!/bin/bash
#slim down jre
if [ -z ${JRE_PATH} ]; then
echo "Define a JRE_PATH env.var"
exit 1;
fi;
if [ ! -d ${JRE_PATH} ] ;then
echo "Please specify path to a JRE"
def auto_props(cls):
gm2m_fields = map( lambda x: x[0],
filter(lambda x: isinstance(x[1], GM2MField), cls._meta._forward_fields_map.items()))
for field in gm2m_fields:
for model in getattr(cls, field).get_related_models(include_auto=True):
model_lower = model.lower()
if not hasattr(cls, model_lower):
setattr(cls, model_lower, property(lambda self:
@ragne
ragne / db.py
Created February 28, 2017 20:17
def handle_err(self):
"""It's a hack. Be careful!
By design it needs self for error storage.
Think of it like windows get_last_error"""
def wrapper(f):
from functools import update_wrapper
def new_func(*args, **kwargs):
try:
res = f(*args, **kwargs)
if isinstance(res, records.RecordCollection):
@ragne
ragne / meta.py
Last active February 6, 2017 14:22
def handle_err(self):
"""It's a hack. Be careful!
By design it needs self for error storage.
Think of it like windows get_last_error"""
def wrapper(f):
from functools import update_wrapper
def new_func(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e: