Skip to content

Instantly share code, notes, and snippets.

View stivenson's full-sized avatar
🏠
Working from home

Stivenson stivenson

🏠
Working from home
View GitHub Profile
@stivenson
stivenson / Image.php
Last active June 22, 2020 14:03
Clase php para operaciones sobre una imagen en base64 o en Archivo
<?php
namespace Helpers; // Optional
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
@stivenson
stivenson / OperationsDate.php
Created April 26, 2016 19:43
Clase para operaciones sobre fechas
<?php
namespace Helpers;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*
*/
@stivenson
stivenson / example-basic-closure.rs
Last active July 3, 2019 17:29
Basic example of closure with a heavy logic
let result = |word| {
// Heavy logic //
let fname = "text_to_find.txt";
// Contents of file
let contents = fs::read_to_string(fname).expect("Something went wrong reading the file");
// Search a word into file's content
match contents.find(word) {
Some(v) => v as u64,
None => 0
@stivenson
stivenson / example-macro.js
Created July 3, 2019 16:45
Example macro in rust-lang
const VALUES_COP: &'static [i32;4] = &[50000, 20000, 10000, 2000];
// macro called cashier
macro_rules! cashier {
() => { // without arguments
println!("Now is necessary that you enter a quantity.");
};
($($x: expr),+) => { // 1 to n arguments
{
let mut total: u64 = 0;
@stivenson
stivenson / new-trait-to-man-struct.rs
Created July 1, 2019 02:54
Example of new trait to man struct
// other Code ...
trait Travel {
fn new(destination: &'static str) -> Self;
fn go(&self) -> &'static str;
}
impl Travel for Man {
fn new(destination: &'static str) -> Man {
// logic ...
@stivenson
stivenson / example-struct-trait-impl.rs
Created July 1, 2019 01:20
Example use of Struct, Trait and impl in rust-lang
struct Man {
name: &'static str,
cellphone: i64,
is_alive: bool,
}
trait Person {
fn new(name: &'static str, cellphone: &i64) -> Self;
fn name(&self) -> &'static str;
fn is_alive(&self) -> &bool;
@stivenson
stivenson / flicker.css
Created December 23, 2017 20:38
Flicker color on div
.background-flicker {
background-color: #FFF;
animation: flicker 2s;
-webkit-animation: flicker 2s;
-moz-animation: flicker 2s;
animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite
}
@stivenson
stivenson / app.js
Created May 13, 2017 06:30 — forked from tobyzerner/app.js
Mithril ES6 Components
import Component from './component';
class Widget extends Component {
init(ctrl) {
var props = this.props;
ctrl.counter = props.initialValue;
ctrl.increment = function() {
ctrl.counter++;
@stivenson
stivenson / account.js
Created May 12, 2017 16:07 — forked from fernandez14/account.js
Mithril 1.x component example.
import m from 'mithril';
import stream from 'mithril/stream';
import {Button} from '../../ui';
import {Account} from '../../models';
export const FormAccountPublicPage = {
oninit(vnode) {
this.loading = true;
this.saving = false;
this.errors = false;
@stivenson
stivenson / 1-sleep-es7.js
Created May 1, 2017 02:40 — forked from danharper/1-sleep-es7.js
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()