Skip to content

Instantly share code, notes, and snippets.

@RonenNess
RonenNess / Python 2 unicode converters (deprecated)
Last active January 17, 2018 11:34
two useful python function to switch between str and unicode
def to_str(text):
'''
convert unicode to string
'''
try:
return str(text)
except:
return str(text.encode("utf-8"))
def to_unicode(text):
@RonenNess
RonenNess / Math utils for nodejs
Last active January 17, 2018 11:34
Some useful math utils for nodejs.
/**
* Provide extended math utilities.
*
* Author: Ronen Ness.
* Since: 2017.
*/
"use strict";
/**
* Provide extended math utilities.
@RonenNess
RonenNess / Django basic log config
Created January 17, 2018 11:33
Django basic log config - creates file and console handlers and add all installed apps by default to the main log file.
# Dump this at the end of your setting file.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
import threading
import socket
# listening to socket with random port
sd = socket.socket(socket.AF_INET)
sd.bind(('127.0.0.1', 0))
ip, port = sd.getsockname()
sd.listen(5)
# connect to socket from "client" side
@RonenNess
RonenNess / MathHelper.cs
Last active April 2, 2023 13:44
Simple C# Math helper with some radians / degrees related functions
/// <summary>
/// Add extended math utils.
/// </summary>
public static class MathHelper
{
/// <summary>
/// PI x 2 value.
/// </summary>
public static readonly float PI2 = (float)Math.PI * 2;
@RonenNess
RonenNess / split_logs.py
Created August 25, 2019 15:37
Tiny script to break large log files into multiple log files. Can work on any type of file, not just logs.
import sys
import os
# print usage
if len(sys.argv) < 2:
print ("Usage: split_logs.py filename [lines_per_file]")
exit(1)
# get filename
filename = sys.argv[1]
@RonenNess
RonenNess / resize_and_rotate.py
Last active March 6, 2022 20:56
A simple python script to resize and rotate all images in a folder.
"""
Run this script from a folder with image files to resize them all to a desired width.
Set 'DESIRED_WIDTH' to choose output images width (height will be calculated automatically to preserve ratio).
Set 'ROTATION' to optionally rotate image before resizing.
Set 'EXTENSIONS' to change what type of files to process.
Note: requires PIL package.
"""
import os
from PIL import Image
import shutil
@RonenNess
RonenNess / XmlFiles
Created April 4, 2020 17:01
Simple C# static class to read and write XML files (serialize any C# class). Throw exception on any error.
/// <summary>
/// Save / load XML files.
/// </summary>
public static class XmlFiles
{
/// <summary>
/// Show last XML file read. For debug purposes.
/// </summary>
public static string LastReadFile { get; private set; }
@RonenNess
RonenNess / pixelator_batch_process.py
Last active March 10, 2023 16:59
A utility script to batch-process files recursively using Pixelator (http://pixelatorapp.com/)
"""
INSTRUCTIONS:
Replace command = '''...''' with the desired pixelator command you want to run recursively.
To get the command you want, you can click on View --> Shell Command from Pixelator GUI.
WARNING:
This will replace the original files! If you want to create a copy, change the following line:
full_command = command.replace('__in_file__', fullpath).replace('__out_file__', fullpath)
To something like:
@RonenNess
RonenNess / DynamicClassLoader
Created January 25, 2021 15:31
Example on how to dynamically compile and load C# classes in runtime.
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis.Emit;
namespace CSharpDynamicCompileExample