Skip to content

Instantly share code, notes, and snippets.

@etigui
etigui / conf.md
Last active March 8, 2019 11:51
Grub does not load after BIOS update (Ubuntu/Windows)

Fix

  1. Run the Windows command prompt (cmd.exe) with Administrator privileges.

  2. Run this commands to make Grub as the default boot manager:

    bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi 
    
  3. Restart the computer, then you should see again the Grub menu with both Windows and Ubuntu.

Ref

@etigui
etigui / program.cs
Created March 2, 2019 18:22
Hide and show console
using ...;
namespace test {
class Program {
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
@etigui
etigui / program.cs
Last active March 2, 2019 17:29
Create and delete password from the memory
using ...;
namespace test {
class Program {
// Call this function to remove the password from memory after use for security
[DllImport("KERNEL32.DLL", EntryPoint = "RtlZeroMemory")]
public static extern bool ZeroMemory(IntPtr Destination, int Length);
private static void Main(string[] args) {
@etigui
etigui / security.cs
Created March 2, 2019 17:20
Encrypt and Decrypt file with TripleDES
using...;
namespace test {
class Security {
private readonly string KEY = "9hqAcoV7ytrRcoHF!EZDiOy1"; // 24
private readonly string IV = "Zcb7H6&A"; // 8
private readonly string ETO = "___EOT";
public void EncryptFile(string inputFile, string outputFile) {
@etigui
etigui / program.cs
Last active March 2, 2019 17:11
Random string (LINQ method)
using ...;
namespace test {
class Program {
private static Random random = new Random();
private static void Main(string[] args) {
Console.WriteLine(RandomString(42));
Console.ReadKey();
@etigui
etigui / program.cs
Last active March 2, 2019 17:07
Create file with random byte
/// <summary>
/// Create file with random byte
/// </summary>
/// <param name="fileName"></param>
/// <param name="sizeMB">Size in MB</param>
private static void CreateRandomByteFile(string fileName, int sizeMB) {
byte[] data = new byte[8192];
Random rng = new Random();
// Create file with random bytes
@etigui
etigui / program.cs
Last active March 2, 2019 17:07
Running external process and redirect standard output in current console
using ...;
namespace test {
class Program {
private static void Main(string[] args) {
RunProcess();
}
private static void RunProcess() {
Process process = new Process();
@etigui
etigui / program.cs
Last active March 2, 2019 17:07
Running external process using new shell
using ...;
namespace test {
class Program {
private static void Main(string[] args) {
RunProcess();
}
private static void RunProcess() {
@etigui
etigui / program.cs
Created March 2, 2019 16:47
Running console minimized
using ...;
namespace test {
class Program {
[DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow);
private static void Main(string[] args) {
ShowWindow(Process.GetCurrentProcess().MainWindowHandle, 6);
@etigui
etigui / globals_locals.py
Created February 7, 2019 23:34
Get globals and locals variables with Python (PyTricks)
# "globals()" returns a dict
# with all global variables
# in the current scope:
>>> globals()
{...}
# "locals()" does the same
# but for all local variables
# in the current scope: