Skip to content

Instantly share code, notes, and snippets.

View 0x49D1's full-sized avatar
💭
💾

Dmitry Pursanov 0x49D1

💭
💾
View GitHub Profile
@0x49D1
0x49D1 / 100years.py
Created September 6, 2016 18:45
Asks user for his birthyear and shows what year he hits 100
import datetime
# Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old.
one_hundred_years = datetime.date.today().year - int(input("Enter your age:\n")) + 100
print_count = input("How many times do you want to print it?\n")
for i in range(int(print_count)):
print("%s You will hit 100 years on %s"%(i+1,one_hundred_years))
@0x49D1
0x49D1 / evenodd.py
Created September 7, 2016 17:17
Even or Odd?
entered_number = int(input("Enter the number and i will tell you is it EVEN or ODD\n"))
if entered_number % 2 == 0:
if entered_number % 4 == 0:
print("Its EVEN, but also /4!")
else :
print("You've entered EVEN number!")
else:
print("You've entered ODD number!")
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
print("Printing numbers less then 5 \n")
print([t for t in a if t < 5])
@0x49D1
0x49D1 / GeoEngTranslit.cs
Last active October 10, 2016 07:26
Snippet to help make Eng -> Geo and Geo -> Eng transliteration in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class GeoEngTranslit
{
static readonly Dictionary<char, string> EngGeoDictionary = new Dictionary<char, string>()
{
{'a',"ა"},
@0x49D1
0x49D1 / sample.cs
Last active February 6, 2023 09:04
Run python script in initialized process
public string run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "PATH_TO_PYTHON_EXE";
start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args);
start.UseShellExecute = false;// Do not use OS shell
start.CreateNoWindow = true; // We don't need new window
start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
using (Process process = Process.Start(start))
@0x49D1
0x49D1 / sample.cs
Last active November 22, 2023 04:34
Sample using IronPython
public string PatchParameter(string parameter, int serviceid)
{
var engine = Python.CreateEngine(); // Extract Python language engine from their grasp
var scope = engine.CreateScope(); // Introduce Python namespace (scope)
var d = new Dictionary<string, object>
{
{ "serviceid", serviceid},
{ "parameter", parameter}
}; // Add some sample parameters. Notice that there is no need in specifically setting the object type, interpreter will do that part for us in the script properly with high probability
@0x49D1
0x49D1 / PollySample.cs
Last active May 2, 2017 17:40
Polly sample
using System;
using Polly;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
// Retry a specified number of times, using a function to
@0x49D1
0x49D1 / escltr.cs
Last active August 25, 2017 08:23
Escape LTR/RTL/TAB/Line endings
string t = Regex.Replace("\u2649\u0009010\u200F260\\15200F609", @"[\u0009\u200F\u200E\u000D]", "");
Console.WriteLine(t); // \u0009 - TAB, \u200F - RTL, \u200E - LTR, \u000D - new line (carriage return char (cr)) and this will leave only: ?10260\15200F609
@0x49D1
0x49D1 / capture_stdout_pytest_sample.py
Created January 16, 2019 08:22
Want print information with "print" statements in pytest? See the sample
#!/usr/bin/python
"""
Run the script like: $ pytest -s test_stdout_stderr.py
-s shortcut for --capture=no
"""
import sys
def test_hello():
print("hello testing")
@0x49D1
0x49D1 / python_log_flask_and_gunicorn_sample.ini
Last active January 17, 2019 09:45
Sample of python logging configuration with log to stdout (console) and syslog
[loggers]
keys=root, gunicorn.error, gunicorn.access, requests.packages.urllib3.connectionpool, __main__
[handlers]
keys=log_file, syslog
[formatters]
keys=generic
[logger_root]