Skip to content

Instantly share code, notes, and snippets.

@JSila
JSila / main.rs
Created July 17, 2023 17:43
deno_core example in rust
use deno_core::v8::{self};
use deno_core::{JsRuntime, RuntimeOptions};
fn main() {
let script1 = std::fs::read_to_string("script1.js").unwrap();
let script2 = std::fs::read_to_string("script2.js").unwrap();
let mut runtime = JsRuntime::new(RuntimeOptions::default());
let _ = runtime.execute_script("script1", script1.into()).unwrap();
@JSila
JSila / main.rs
Last active July 21, 2020 07:51
Rust: example of using channels to communicate between threads (mutiple producers, single consumer)
use std::sync::mpsc::channel;
use chrono::{DateTime, Local};
use threadpool::ThreadPool;
#[derive(Debug)]
struct Site {
id: String,
url: String,
changed: Option<bool>,
@JSila
JSila / main.rs
Last active July 21, 2020 07:49
Rust: updating an array field of mutable struct in a seperate function
use std::env;
use std::fs::File;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Site {
id: String,
#[serde(skip_serializing_if = "Option::is_none")]
status_changed: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
@JSila
JSila / aliases-cl.sh
Created April 14, 2014 22:46
Bash aliases for most used commands - composer and laravel
alias c="composer"
alias ccp="composer create-project --prefer-dist"
alias csu="sudo composer self-update"
alias cu="composer update"
alias ci="composer install"
alias cr="composer require"
alias csh="composer show"
alias cse="composer search"
alias cda="composer dump-autoload -o"
@JSila
JSila / WP_Settings.php
Last active September 2, 2019 21:47
WP Settings API in OOP way
<?php
class WP_Settings_Section {
protected $id = '';
protected $title = '';
protected $output_callback = '';
protected $fields = array();
public function __construct($id, $title, $output_callback) {
$this->id = $id;
@JSila
JSila / withForm-1.js
Last active April 30, 2018 09:59
withForm higher-order component
import React from "react"
const noop = () => false
const withForm = (fields, validateFn = noop, validSubmitFn) => WrappedComponent => {
class WithForm extends React.Component {
constructor(props) {
super(props)
this.state = {
@JSila
JSila / router.js
Created April 23, 2018 14:10
custom router solution for react (experiment)
import React, {Component, createElement} from 'react'
import createHistory from 'history/createBrowserHistory'
import classnames from "classnames"
export const history = createHistory()
/**
* Determines if route path matches history location's pathname. If it does, extracts its params. If not, returns null.
*
* @param routePath
@JSila
JSila / index.js
Created March 4, 2018 13:28
Helpers for providing and consuming multiple react contexts
import React, {Component} from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import createContext from 'create-react-context'
const Theme = createContext("light")
const Language = createContext("en")
const Whatever = createContext("whatever")
@JSila
JSila / client.go
Last active October 4, 2017 16:58
Context cancelation example in Go
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"net/http"
"time"
)
@JSila
JSila / App.js
Created January 12, 2017 14:26
Example of showing/hiding Twitter Bootstrap (4) modal - with react, not jquery
import React, { Component } from 'react'
import Modal from './Modal'
export default class extends Component {
constructor(props) {
super(props)
this.state = {
isOpen: false