extern crate gl;
extern crate sdl2;
// pub mod render_gl;
use self::gl::types::*;
use std::ffi::CString;
use std::mem;
use std::os::raw::c_void;
use std::ptr;
use std::str;
use std::sync::mpsc::Receiver;
const vertexShaderSource: &str = r#"
#version 330 core
layout (location = 0) in vec3 aPos;
void main() {
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
"#;
const fragmentShaderSource: &str = r#"
#version 330 core
out vec4 FragColor;
void main() {
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}
"#;
fn main() {
let sdl = sdl2::init().unwrap();
let video_subsystem = sdl.video().unwrap();
let gl_attr = video_subsystem.gl_attr();
gl_attr.set_context_profile(sdl2::video::GLProfile::Core);
gl_attr.set_context_version(4, 1);
let window = video_subsystem
.window("Game", 900, 700)
.opengl()
.resizable()
.build()
.unwrap();
let _gl_context = window.gl_create_context().unwrap();
let _gl =
gl::load_with(|s| video_subsystem.gl_get_proc_address(s) as *const std::os::raw::c_void);
let (shaderProgram, VAO) = unsafe {
// build and compile our shader program
// ------------------------------------
// vertex shader
let vertexShader = gl::CreateShader(gl::VERTEX_SHADER);
let c_str_vert = CString::new(vertexShaderSource.as_bytes()).unwrap();
gl::ShaderSource(vertexShader, 1, &c_str_vert.as_ptr(), ptr::null());
gl::CompileShader(vertexShader);
// check for shader compile errors
let mut success = gl::FALSE as GLint;
let mut infoLog = Vec::with_capacity(512);
infoLog.set_len(512 - 1); // subtract 1 to skip the trailing null character
gl::GetShaderiv(vertexShader, gl::COMPILE_STATUS, &mut success);
if success != gl::TRUE as GLint {
gl::GetShaderInfoLog(
vertexShader,
512,
ptr::null_mut(),
infoLog.as_mut_ptr() as *mut GLchar,
);
println!(
"ERROR::SHADER::VERTEX::COMPILATION_FAILED\n{}",
str::from_utf8(&infoLog).unwrap()
);
}
// fragment shader
let fragmentShader = gl::CreateShader(gl::FRAGMENT_SHADER);
let c_str_frag = CString::new(fragmentShaderSource.as_bytes()).unwrap();
gl::ShaderSource(fragmentShader, 1, &c_str_frag.as_ptr(), ptr::null());
gl::CompileShader(fragmentShader);
// check for shader compile errors
gl::GetShaderiv(fragmentShader, gl::COMPILE_STATUS, &mut success);
if success != gl::TRUE as GLint {
gl::GetShaderInfoLog(
fragmentShader,
512,
ptr::null_mut(),
infoLog.as_mut_ptr() as *mut GLchar,
);
println!(
"ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n{}",
str::from_utf8(&infoLog).unwrap()
);
}
// link shaders
let shaderProgram = gl::CreateProgram();
gl::AttachShader(shaderProgram, vertexShader);
gl::AttachShader(shaderProgram, fragmentShader);
gl::LinkProgram(shaderProgram);
// check for linking errors
gl::GetProgramiv(shaderProgram, gl::LINK_STATUS, &mut success);
if success != gl::TRUE as GLint {
gl::GetProgramInfoLog(
shaderProgram,
512,
ptr::null_mut(),
infoLog.as_mut_ptr() as *mut GLchar,
);
println!(
"ERROR::SHADER::PROGRAM::COMPILATION_FAILED\n{}",
str::from_utf8(&infoLog).unwrap()
);
}
gl::DeleteShader(vertexShader);
gl::DeleteShader(fragmentShader);
// HINT: type annotation is crucial since default for float literals is f64
let vertices: [f32; 12] = [
0.5, 0.5, 0.0, // top right
0.5, -0.5, 0.0, // bottom right
-0.5, -0.5, 0.0, // bottom left
-0.5, 0.5, 0.0, // top left
];
let indices = [
0, 1, 3, // first Triangle
1, 2, 3, // second Triangle
];
let (mut VBO, mut VAO, mut EBO) = (0, 0, 0);
gl::GenVertexArrays(1, &mut VAO);
gl::GenBuffers(1, &mut VBO);
gl::GenBuffers(1, &mut EBO);
gl::BindVertexArray(VAO);
gl::BindBuffer(gl::ARRAY_BUFFER, VBO);
gl::BufferData(
gl::ARRAY_BUFFER,
(vertices.len() * mem::size_of::<GLfloat>()) as GLsizeiptr,
&vertices[0] as *const f32 as *const c_void,
gl::STATIC_DRAW,
);
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, EBO);
gl::BufferData(
gl::ELEMENT_ARRAY_BUFFER,
(indices.len() * mem::size_of::<GLfloat>()) as GLsizeiptr,
&indices[0] as *const i32 as *const c_void,
gl::STATIC_DRAW,
);
gl::VertexAttribPointer(
0,
3,
gl::FLOAT,
gl::FALSE,
3 * mem::size_of::<GLfloat>() as GLsizei,
ptr::null(),
);
gl::EnableVertexAttribArray(0);
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
gl::BindVertexArray(0);
(shaderProgram, VAO)
};
let mut event_pump = sdl.event_pump().unwrap();
'main: loop {
for event in event_pump.poll_iter() {
match event {
sdl2::event::Event::Quit { .. } => break 'main,
_ => {}
}
}
unsafe {
gl::ClearColor(0.2, 0.3, 0.3, 1.0);
gl::Clear(gl::COLOR_BUFFER_BIT);
// draw our first triangle
gl::UseProgram(shaderProgram);
gl::BindVertexArray(VAO); // seeing as we only have a single VAO there's no need to bind it every time, but we'll do so to keep things a bit more organized
// gl::DrawArrays(gl::TRIANGLES, 0, 3);
gl::DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, ptr::null());
// glBindVertexArray(0); // no need to unbind it every time
}
window.gl_swap_window();
}
}
.text {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
line-height: 16px; /* fallback */
max-height: 32px; /* fallback */
-webkit-line-clamp: 2; /* number of lines to show */
-webkit-box-orient: vertical;
}
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam consectetur
venenatis blandit. Praesent vehicula, libero non pretium vulputate, lacus arcu
facilisis lectus, sed feugiat tellus nulla eu dolor. Nulla porta bibendum
lectus quis euismod. Aliquam volutpat ultricies porttitor. Cras risus nisi,
accumsan vel cursus ut, sollicitudin vitae dolor. Fusce scelerisque eleifend
lectus in bibendum. Suspendisse lacinia egestas felis a volutpat.
</div>
const obj = {
0: { 0: "01.01.2019", 1: 11111.01 },
1: { 0: "02.01.2019", 1: 22222.02 },
2: { 0: "03.01.2019", 1: 33333.03 }
};
const result = Object.keys(obj).map((value, index) => Object.values(obj[value]));
import util from 'util';
import http from 'http';
function HttpError(status, message) {
Error.apply(this, arguments);
Error.captureStackTrace(this, HttpError);
this.status = status;
this.message = message || http.STATUS_CODES[status] || "Error";
}
util.inherits(HttpError, Error);
HttpError.prototype.name = 'HttpError';
export {HttpError};
import React from "react";
import { render } from "react-dom";
import "./index.css";
const data = [
{ index: 0, product: "Bread", category: "Food", price: 1 },
{
index: 1,
product: 'F. Dostoyevsky "Crime and Punishment"',
category: "Books",
price: 8
},
{ index: 2, product: "iPhone", category: "Electronics", price: 699 },
{ index: 3, product: "Milk", category: "Food", price: 2 },
{ index: 4, product: "TV", category: "Electronics", price: 1099 }
];
class TableRow extends React.Component {
render() {
return (
<tr>
<td>{this.props.index}</td>
<td>{this.props.product}</td>
<td>{this.props.category}</td>
<td>
{"$"}
{this.props.price}
</td>
</tr>
);
}
}
class Table extends React.Component {
constructor(props) {
super(props);
this.state = {
index: true,
product: true,
category: true,
price: true,
data: props.data
};
}
sortByIndex() {
var getIndex = !this.state.index;
var data = this.state.data;
data.sort((a, b) => {
if (!getIndex) {
return b.index - a.index;
} else {
return a.index - b.index;
}
});
this.setState({ data, index: getIndex });
}
sortByProductName() {
var getProduct = !this.state.product;
var data = this.state.data;
data.sort((a, b) => {
if (!getProduct) {
return b.product > a.product;
} else {
return a.product > b.product;
}
});
this.setState({ data, product: getProduct });
}
sortByCategory() {
var getCategory = !this.state.category;
var data = this.state.data;
data.sort((a, b) => {
if (!getCategory) {
return b.category > a.category;
} else {
return a.category > b.category;
}
});
this.setState({ data, category: getCategory });
}
sortByPrice() {
var getPrice = !this.state.price;
var data = this.state.data;
data.sort((a, b) => {
if (!getPrice) {
return b.price - a.price;
} else {
return a.price - b.price;
}
});
this.setState({ data, price: getPrice });
}
render() {
return (
<table className="table">
<tr>
<th onClick={this.sortByIndex.bind(this)}>
Index <i className={this.state.index ? "fa fa-caret-up" : "fa fa-caret-down"} aria-hidden="true" />{" "}
</th>
<th onClick={this.sortByProductName.bind(this)}>
Product <i className={this.state.product ? "fa fa-caret-up" : "fa fa-caret-down"} aria-hidden="true" />{" "}
</th>
<th onClick={this.sortByCategory.bind(this)}>
Category <i className={this.state.category ? "fa fa-caret-up" : "fa fa-caret-down"} aria-hidden="true" />{" "}
</th>
<th onClick={this.sortByPrice.bind(this)}>
Price <i className={this.state.price ? "fa fa-caret-up" : "fa fa-caret-down"} aria-hidden="true" />{" "}
</th>
</tr>
<tbody>{this.state.data.map((element, i) => <TableRow key={Math.random()} index={element.index} product={element.product} category={element.category} price={element.price} />)}</tbody>
</table>
);
}
}
render(<Table data={data} />, document.getElementById("root"));
if(typeof name !== ‘string) throw ‘Name should be string’
let newBuff = Buffer.from('New String');
console.log(newBuff.toString('utf8')); // New String
var StringDecoder = require('string_decoder').StringDecoder;
var d = new StringDecoder('utf8');
var b = Buffer('abc');
console.log(b); // <Buffer 61 62 63>
console.log(d.write(b)); // abc
"use strict";
this.setState({
displayed: containerWidth <= 719 ? 1 : 3
});