Skip to content

Instantly share code, notes, and snippets.

View andrisgauracs's full-sized avatar

Andris Gauračs andrisgauracs

View GitHub Profile
@andrisgauracs
andrisgauracs / asynchornous_traditional.jsx
Last active December 30, 2018 22:01
Traditional React asynchornous data call
class TraditionalAsyncExample extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
resource: undefined
}
}
componentDidMount() {
fetch(`{resourse}`).then((e)=>{
@andrisgauracs
andrisgauracs / picsum_imgs.jsx
Last active December 30, 2018 22:01
Getting random images from picsum.photos
const files = [];
for (let i = 0; i < 20; i++) {
let pictureNr = Math.floor(Math.random() * 100);
files.push({
large: `https://picsum.photos/1920/1080/?image=${pictureNr}`,
small: `https://picsum.photos/200/113/?image=${pictureNr}`
})
}
this.state = {
images: files
@andrisgauracs
andrisgauracs / react_cache.jsx
Last active December 30, 2018 22:01
A new img component, that will act just like the basic img tag, but in addition will provided an asynchronous image preload
/* We utilize the createResource provied by React,
which allows to access the image data asynchronously */
const ImageResource = unstable_createResource(
source =>
new Promise(resolve => {
const img = new Image();
img.src = source;
img.onload = resolve;
})
);
@andrisgauracs
andrisgauracs / image_wrapper_component.jsx
Last active December 30, 2018 22:00
An image wrapper component, that holds all of our data inside it, plus it get triggered to run only when scrolled into view
/* an image wrapper component, that holds
all of our data inside it, plus it
get triggered to run only when scrolled into view. */
const ImageWrapper = ({ image, nr, render }) => (
render ?
<ImageContainer>
<Suspense fallback={
<ImageContainer> {/* This gets shown while the full res image is preloading */}
<img className="blurry" src={image.small} alt={`img_small_${nr}`}/>
{/* This gets shown below while the low res image is preloading */}
{(this.state.images.map((e,i)=>
<InViewMonitor key={i} childPropsInView={{render: true}}>
<ImageWrapper image={e} nr={i}/>
</InViewMonitor>
))}
@andrisgauracs
andrisgauracs / comment_out.py
Created January 10, 2019 21:43
Comment this out in the original VLC file
'''if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
player = Player()
player.show()
player.resize(640, 480)
if sys.argv[1:]:
player.OpenFile(sys.argv[1])
sys.exit(app.exec_())'''
@andrisgauracs
andrisgauracs / variables.py
Created January 10, 2019 21:45
Required variables for color palette generator
# Global variables
framesTaken = 0
framesTakenList = []
framesSpecified = 0
clusters = 5
margin = 5
borderSize = 40
offset = 2
@andrisgauracs
andrisgauracs / custom_class.py
Created January 10, 2019 21:46
We define our custom VLC Player class
# We define our custom VLC Player class
class Custom_VLC_Player(Player):
def __init__(self):
# We inherit all the attributes of the original class
super(Custom_VLC_Player, self).__init__()
@andrisgauracs
andrisgauracs / QtGUI_app.py
Created January 10, 2019 21:47
Initialize the QtGUI Application instance
# Initialize the QtGUI Application instance
app = QtGui.QApplication(sys.argv)
# Initialize our custom VLC Player instance
vlc = Custom_VLC_Player()
vlc.show()
# Let's change the size of the window. We will make it 660px by 530px
vlc.resize(660, 530)
if sys.argv[1:]:
class Custom_VLC_Player(Player):
def __init__(self):
# We inherit all the attributes of the original class
super(Custom_VLC_Player, self).__init__()
# We want the width and height to be fixed, so the layout dimensions
# don't change in a weird way
self.videoframe.setFixedWidth(640)
self.videoframe.setFixedHeight(360)