Skip to content

Instantly share code, notes, and snippets.

View Raymai97's full-sized avatar
@nullable response

Raymai (Chee Boon) Raymai97

@nullable response
  • CardBiz Solutions Sdn Bhd
  • Malaysia
  • X @raymai97
View GitHub Profile
@Raymai97
Raymai97 / getss.c
Created May 19, 2022 01:06
gets() replacement
#include <stdio.h>
#include <string.h>
/*
Return < 0 if EOF (user pressed CTRL+Z or CTRL+D)
Return == 0 if input fits in buffer nicely
Return > 0 if <return value> chars are truncated to fit buffer
For example, if return 2, 2 chars are truncated to fit buffer
*/
int getss(char *psz, int bufsize)
@Raymai97
Raymai97 / Assets.java
Created February 11, 2020 14:14
Android Assets Util
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import androidx.annotation.NonNull;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@Raymai97
Raymai97 / WakeScreen.java
Created February 11, 2020 02:50
Android WakeScreen
import android.os.PowerManager;
import androidx.annotation.NonNull;
public class WakeScreen {
/**
* Wake device screen as if user pressed power button. No force always on.
*/
public static void wakeScreen(@NonNull PowerManager powerManager,
@NonNull String randomTag) {
@Raymai97
Raymai97 / CreateLnkShortcut.cpp
Created September 19, 2016 07:07
Simple function to create shortcut (.lnk)
// NOT FINISH YET
#include <Windows.h>
#include <tchar.h>
#include <ShlObj.h>
#include <ShlGuid.h>
bool CreateLnkShortcut(LPCTSTR szLnkPath, LPCTSTR szTargetPath) {
bool ret = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
@Raymai97
Raymai97 / GetPickedDir.cpp
Last active September 19, 2016 15:24
Simple function for using Vista Pick Folder Dialog
// Must compile using Unicode character set;
// IFileDialog doesn't support non-Unicode.
// I'm using TCHAR because I'm get used to it.
#include <Windows.h>
#include <tchar.h>
#include <ShlObj.h>
#include <ShlGuid.h>
#include <strsafe.h> // StringCchCopy is better than _tcscpy_s in this case
@Raymai97
Raymai97 / RefreshExplorer.vb
Last active August 29, 2015 14:19
Refresh Explorer (apply settings in registry immediately) without restarting Explorer. Most of the time it works, unless you're using bullheaded OS like Windows 8/8.1...
Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Int32, _
ByVal uFlags As Int32, ByVal dwItem1 As Int32, ByVal dwItem2 As Int32) As Int32
Sub RefreshExplorer()
SHChangeNotify(&H8000000, &H0, 0, 0)
Dim CLSID_ShellApplication As New Guid("13709620-C279-11CE-A49E-444553540000")
Dim shellApplicationType As Type = Type.GetTypeFromCLSID(CLSID_ShellApplication, True)
Dim shellApplication As Object = Activator.CreateInstance(shellApplicationType)
Dim windows As Object = shellApplicationType.InvokeMember("Windows", _
System.Reflection.BindingFlags.InvokeMethod, Nothing, shellApplication, New Object() {})
@Raymai97
Raymai97 / OSVerTeller.vb
Created April 23, 2015 04:01
Get string of Windows operating system version with details. Service Pack and Build Number are included.
Dim OSVer as String
Try
Dim Key As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion")
Dim ProductName As Object = Key.GetValue("ProductName")
Dim CurrentVersion As Object = Key.GetValue("CurrentVersion")
Dim CurrentBuildNumber As Object = Key.GetValue("CurrentBuildNumber")
Dim CSDVersion As Object = Key.GetValue("CSDVersion")
Dim BuildLabEx As Object = Key.GetValue("BuildLabEx")
OSVer = ProductName.ToString()
If CSDVersion IsNot Nothing Then
@Raymai97
Raymai97 / RijCrypto.vb
Created March 27, 2013 08:56
[VB.NET] A simple class that encrypt and decrypt the bytes, with the RijndaelManaged class in .NET. It's not very secure though, as it uses CipherMode.ECB, but should enough for daily use.
'IMPORTANT TIPS for using RijndaelManaged class
'The key must in 128bit or 256bit, to make 128bit key compose the MD5 hash of the Password String
'The mode must set to ECB, if you only want simple encryption.
'Must CreateEncryptor/CreateDecryptor AFTER AND ONLY AFTER you set the Key and Mode!
Imports System.Security.Cryptography
Public Class RijCrypto
Public Shared LastErr as String