Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / Example.cs
Created May 8, 2020 17:20
Unity C# : Structs vs CLass
public class FooClass
{
public string name;
}
public struct FooStruct
{
public string name;
}
public static class Example
@openroomxyz
openroomxyz / HowToCloseTheGameOnEscKey.cs
Created May 4, 2020 12:01
Unity : How to close the game on esc key?
//Works only in build game, does not work when run inside editor
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
@openroomxyz
openroomxyz / HowToInstancimateFromResourceFolderAtRuntime.cs
Last active May 4, 2020 12:04
Unity : How to Instantiate a prefab from resource folder, by name? [Works in Build and Editor! ]
GameObject my_game_object = (GameObject)Resources.Load("BIP", typeof(GameObject));
Instantiate(my_game_object);
Instantiate(my_game_object); //we can Instantiate the prefab many times and creates mane game object from it
my_game_object = null;
@openroomxyz
openroomxyz / SetBitInByte.cs
Last active May 2, 2020 11:05
Unity C# : How to set a bit in byte to 0 or 1 ?
//Writing
//Set bit to 1
my_byte = my_byte | (1 << pos); // longer version, or
my_byte |= 1 << pos; // shorthand
//Set bit to 0
my_byte = my_byte & ~(1 << pos); // longer version, or
my_byte &= ~(1 << pos); // shorthand
//Reading
var bit = (b & (1 << bitNumber-1)) != 0;
@openroomxyz
openroomxyz / WordpressAPI_CreatePost.py
Created April 24, 2020 12:05
Python WordPressAPI : How to create a post?
import base64, requests, json
def header(user, password):
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header_json = {'Authorization': 'Basic ' + token.decode('utf-8')}
return header_json
def create_post(content,title, url, header_json):
post = {
@openroomxyz
openroomxyz / WordpressAPI_CreatePAGE.py
Last active April 24, 2020 11:55
Python WordPressAPI : How to create a PAGE ?
import base64, requests, json
def header(user, password):
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header_json = {'Authorization': 'Basic ' + token.decode('utf-8')}
return header_json
def create_page(content,title, url, header_json):
post = {
@openroomxyz
openroomxyz / WordpressAPI_UploadImage.py
Last active August 4, 2024 15:28
Python WordPress API : How to upload image to wordpress?
import base64, requests, json
def header(user, password):
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header_json = {'Authorization': 'Basic ' + token.decode('utf-8')}
return header_json
def upload_image_to_wordpress(file_path, url, header_json):
media = {'file': open(file_path,"rb"),'caption': 'My great demo picture'}
@openroomxyz
openroomxyz / GetListOfFilesInFolder.cs
Last active April 23, 2020 16:51
Unity : How to get a list of path -s to all files (only files excluding sub folders ) in some folder?
private static List<string> GetListOfFilesInFolder(string path)
{
string[] fileEntries = System.IO.Directory.GetFiles(path);
List<string> result = new List<string>();
foreach(string f in fileEntries)
{
if(System.IO.File.Exists(f))
{
result.Add(f);
}
@openroomxyz
openroomxyz / GetAllURLSOnPageHtmlOnly.py
Created April 22, 2020 20:36
Python : How can i get get all url -s on page ? (html only)
import bs4 as bs
import urllib.request
sauce = urllib.request.urlopen('https://singularityhub.com/').read()
soup = bs.BeautifulSoup(sauce, 'lxml')
for url in soup.find_all('a'):
#print(url)
print(url.text)
print(url.get('href'))
@openroomxyz
openroomxyz / Crawler.py
Last active April 22, 2020 20:27
Python : How to get a list of all URLs on some domain crawling from page to page on that domain?
import bs4 as bs
import urllib.request
import time
def filter_to(input_list,limit_to):
res = []
for i in input_list:
if i is not None:
if limit_to in i:
res.append(i)