Skip to content

Instantly share code, notes, and snippets.

View ydcool's full-sized avatar
:octocat:
Focusing

Dominic Yin ydcool

:octocat:
Focusing
View GitHub Profile
@taylorza
taylorza / GO-Fillslice.md
Last active April 5, 2024 12:52
Golang - Fill slice/array with a pattern

Filling an array or slice with a repeated pattern

Looking for an efficient pure GO approach to copy repeating patterns into a slice, for a toy project, I ran a few tests and discovered a neat approach to significantly improve performance. For the toy project, I am using this to fill a background buffer with a specific RGB color pattern, so improving this performance significantly improved my acheivable framerate.

All the test were run with a buffer of 73437 bytes, allocated as follows

var bigSlice = make([]byte, 73437, 73437)

Fill the slice with the value 65 by looping through each element and setting the value

@NaniteFactory
NaniteFactory / messagebox.go
Last active April 24, 2024 17:58
Win32 API MessageBox() in Golang
import (
"syscall"
"unsafe"
)
// MessageBox of Win32 API.
func MessageBox(hwnd uintptr, caption, title string, flags uint) int {
ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))),
@stefangordon
stefangordon / mjpegexample.js
Created December 21, 2016 16:13
React Native MJPEG
var styles = StyleSheet.create({
backgroundVideo: {
width:400,
height:322
}
})
return (
<View>
<WebView
@chomi3
chomi3 / ToolbarColorizeHelper
Last active February 11, 2022 23:41
Helper class to colorize all Android Toolbar Icons
/*
Copyright 2015 Michal Pawlowski
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@meoyawn
meoyawn / EmptyRecyclerView.java
Created November 1, 2014 11:20
RecyclerView doesn't have an emptyView support, we gotta fix that
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EmptyRecyclerView extends RecyclerView {
@Nullable View emptyView;
@gabrielemariotti
gabrielemariotti / Toolbar.java
Created August 4, 2014 13:22
Android-L: A little example of the new Toolbar view.
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
//Title and subtitle
toolbar.setTitle("MY toolbar");
toolbar.setSubtitle("Subtitle");
//Menu
toolbar.inflateMenu(R.menu.toolbar_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@methodin
methodin / Rotate3dAnimation.java
Last active April 28, 2021 07:25
3d rotation animation for Android
/*
Original code found at:
https://code.google.com/p/android-stocker/source/browse/trunk/src/com/twofuse/stocker/Rotate3dAnimation.java?r=2
Use (in set):
Rotate3dAnimation skew = new Rotate3dAnimation(20, 0, 0, 0, 0, 0);
set.addAnimation(skew);
animation = new TranslateAnimation(0, 0, 0, 0, Animation.RELATIVE_TO_SELF, 0.5f, 0, 0);
set.addAnimation(animation);
@jcxplorer
jcxplorer / uuid.js
Created February 12, 2011 16:58
UUID v4 generator in JavaScript (RFC4122 compliant)
function uuid() {
var uuid = "", i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += "-"
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}