Skip to content

Instantly share code, notes, and snippets.

View benloong's full-sized avatar

benloong benloong

View GitHub Profile
@benloong
benloong / NesteScrollRect.cs
Created December 28, 2022 08:00 — forked from Josef212/NesteScrollRect.cs
A nested ScrollRect for unity
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class NestedScrollRect : ScrollRect
{
public override void OnInitializePotentialDrag(PointerEventData eventData)
{
for(int i = 0; i < m_parentInitializePotentialDragHandlers.Length; ++i)
{
@benloong
benloong / workstealingqueue.cpp
Created March 23, 2019 08:32
work stealing queue
#include <atomic>
class Job;
struct WorkStealingQueue
{
// only called by owner work thread
void Push(Job* job) noexcept
{
// m_bottom -> stealing thread read, owner thread read, write.
@benloong
benloong / README-Template.md
Created January 11, 2019 09:14 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@benloong
benloong / copyContent.js
Last active November 29, 2021 21:48 — forked from coclav/copyContent
Copy file out of ASAR archive for Electron app
var fs = require("fs");
var path = require("path")
var app = require("electron").remote.app;
// var fsj = require("fs-jetpack");
// example usage : copyFileOutsideOfElectronAsar( "myFolderInsideTheAsarFile", app.getPath("temp") + "com.bla.bla"
var copyFileOutsideOfElectronAsar = function (sourceInAsarArchive, destOutsideAsarArchive) {
@benloong
benloong / method.cpp
Last active October 19, 2017 09:59
c++ reflection
#include<any>
#include<tuple>
using any = std::any;
namespace {
constexpr bool strings_equal(char const * a, char const * b) {
return *a == *b && (*a == '\0' || strings_equal(a + 1, b + 1));
template<unsigned... Is> struct seq{};
template<unsigned N, unsigned... Is>
struct gen_seq : gen_seq<N-1, N-1, Is...>{};
template<unsigned... Is>
struct gen_seq<0, Is...> : seq<Is...>{};
enum Type {
Alphabet,
Number,
Symbol,
@benloong
benloong / AssetBundleTool.cs
Created April 11, 2017 02:23
Unity4.x Build AssetBundle and generate dependence
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.Linq;
public class AssetBundleManifest
{
public string AssetPath;
public HashSet<AssetBundleManifest> Parents = new HashSet<AssetBundleManifest>();
public HashSet<AssetBundleManifest> Children = new HashSet<AssetBundleManifest>();
// http:// stackoverflow.com/questions/23202489/how-does-this-code-find-the-number-of-trailing-zeros-from-any-base-number-factor
// https://comeoncodeon.wordpress.com/2010/02/17/number-of-zeores-and-digits-in-n-factorial-in-base-b/
function zeroes (base, number) {
var noz = Number.MAX_VALUE;
// Now we can break the Base B as a product of primes :
// B = a^p1 * b^p2 * c^p3 * …
//Then the number of trailing zeroes in N factorial in Base B is given by the formulae
// min{1/p1(n/a + n/(a*a) + ….), 1/p2(n/b + n/(b*b) + ..), ….}.
var j = base;
@benloong
benloong / test.cpp
Last active January 16, 2017 01:32
C++17 generic callable profiling.
#include "timed_invoke.h"
int* func0(int x, int y, const char* z) {
return nullptr;
}
void func1(int x, const char* z) {
return;
}
@benloong
benloong / PageViewController.cs
Created January 6, 2017 07:18
Unity UI system PageViewController
using System;
using UnityEngine;
using UnityEngine.EventSystems;
public class PageViewController : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IInitializePotentialDragHandler
{
public enum Direction
{
Horizontal,
Vertical