Skip to content

Instantly share code, notes, and snippets.

View Youka's full-sized avatar

Youka Youka

  • Germany
  • 09:49 (UTC +02:00)
View GitHub Profile
@Youka
Youka / network_analysis.ps1
Created September 10, 2017 15:36
Logs used network bandwidth for some time
# Configuration
$run_duration_seconds = 10
$read_delay_milliseconds = 500
$log_file = "log.txt"
$verbose = $true
# Network statistics
$statistics = @{}
$start_time = Get-Date
$end_time = $start_time.addSeconds($run_duration_seconds)
@Youka
Youka / copy_logged.ps1
Created September 10, 2017 13:29
Copy contents from one directory to another and log every step
# Configuration
$src_folder = "./src"
$dst_folder = "./dst"
$log_file = "log.txt"
# Save paths as absolute
$dst_folder = (Get-Item $dst_folder).FullName
$log_file = (Get-Item $log_file).FullName
# Move to source directory
Set-Location -Path $src_folder
@Youka
Youka / hide_console.ps1
Created September 10, 2017 13:26
Powershell process hides console in background
# Hide console
Add-Type -Namespace User32 -Name Functions -MemberDefinition @"
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
"@
[User32.Functions]::ShowWindowAsync((Get-Process -Id $pid).MainWindowHandle, 0)
# Register form objects from .NET
[void][reflection.assembly]::loadwithpartialname("System.Windows.Forms")
# Create & show simple dialog
@Youka
Youka / Main.java
Last active June 6, 2017 01:05
Groovy in Java test
/*
* The MIT License
*
* Copyright 2017 Youka.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@Youka
Youka / twitch_play
Last active March 31, 2016 18:05
Start Twitch stream (with Livestreamer) + chat (with Firefox) after simple channel input
#!/bin/bash
# Ask user for channel
read -p "Enter Twitch channel name: " channel
# Channel name to lowercase
channel=${channel,,}
# Open Twitch chat
read -p "Open chat (y/n): " open_chat
if [ "$open_chat" = "y" ]
@Youka
Youka / Makefile.i686-w64-mingw32
Created March 3, 2016 06:35
Lua 5.3 cross-platform build
CC= i686-w64-mingw32-gcc
CFLAGS= -O3 -Wall -Wextra -std=gnu99 -DLUA_COMPAT_5_2
AR= ar rc
MKDIR= mkdir -p
RM= rm -rf
INSTALL= $(CURDIR)/install
SOURCES= lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c
OBJECTS= $(subst .c,.o,$(SOURCES))
@Youka
Youka / main.cpp
Created February 7, 2016 23:02
Global key listener (Windows)
#include <thread>
#include <atomic>
#include <functional>
#include <windows.h>
static thread_local const std::function<void(WPARAM,DWORD)>* LLKP_data;
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam){
if(nCode == HC_ACTION)
(*LLKP_data)(wParam, reinterpret_cast<PKBDLLHOOKSTRUCT>(lParam)->vkCode);
return CallNextHookEx(NULL, nCode, wParam, lParam);
@Youka
Youka / main.c
Created September 28, 2015 02:15
Calculate Pi
#include <stdlib.h>
#include <stdio.h>
#ifdef __SSE2__
#include <emmintrin.h>
#endif
static double calc_pi(unsigned n){
double pi, x;
#ifdef __SSE2__
const __m128d four = _mm_set1_pd(4.0);
@Youka
Youka / main.c
Last active August 29, 2015 14:25
Performance test of vector division by unsigned short integers - x86 vs. SSE
#include <emmintrin.h> // SSE2
static unsigned short x[8] = {0, 55, 2, 62003, 786, 5555, 123, 32111}; // Dividend
__attribute__((noinline)) static void test_div_x86(unsigned i){
for(; i; --i)
x[0] /= i,
x[1] /= i,
x[2] /= i,
x[3] /= i,
#pragma once
#ifdef _MSC_VER
#include <intrin.h>
#define bit_SSE2 (1 << 26)
#define bit_SSE3 (1 << 0)
#define bit_AVX (1 << 28)
#else
#include <cpuid.h>
#endif // _MSC_VER