Skip to content

Instantly share code, notes, and snippets.

Avatar

Wei Sun saga

View GitHub Profile
@saga
saga / React-Hooks.js
Created Sep 25, 2020 — forked from craigtaub/React-Hooks.js
Nested React Hooks
View React-Hooks.js
// Engine
const React = {
index: 0,
state: [],
useEffect: (callback, dependencies) => {
const cachedIndex = React.index;
const hasChanged = dependencies !== React.state[cachedIndex];
if (dependencies === undefined || hasChanged) {
callback();
View 英文字幕单词提示.py
#!/usr/bin/env python
# coding: utf-8
import pysubs2
import re
from stardict import DictCsv
# depend on https://github.com/skywind3000/ECDICT/
dict_filename="ecdict.csv"
sub_filename="01sub.srt"
@saga
saga / keyup_event.js
Created Jan 29, 2019 — forked from sukima/keyup_event.js
This is how I managed to facilitate keyboard events in multiple browsers
View keyup_event.js
// <input id="my-input-element" type="text" value="foo"/>
var evt, node = document.getElementById('my-input-element');
// Have to use dispatchEvent/fireEvent because jQuery.trigger will not
// fire an event attached via addEventListener. Each environment has an
// unusual way to trigger a keyup event.
if (node.dispatchEvent) {
// Sane browsers
try {
// Chrome, Safari, Firefox
View Free O'Reilly Books.md

Free O'Reilly books and convenient script to just download them.

Thanks /u/FallenAege/ and /u/ShPavel/ from this Reddit post

How to use:

  1. Take the download.sh file and put it into a directory where you want the files to be saved.
  2. cd into the directory and make sure that it has executable permissions (chmod +x download.sh should do it)
  3. Run ./download.sh and wee there it goes. Also if you do not want all the files, just simply comment the ones you do not want.
View setting.js
{
// Controls the font family.
"editor.fontFamily": "Fira Code Light, Consolas, monospace",
"http.proxy": "",
"window.restoreWindows": "none",
"editor.fontSize": 15,
"editor.accessibilitySupport": "off",
"editor.tabCompletion": true,
@saga
saga / UserValidator.cs
Created Sep 13, 2017 — forked from GrantByrne/UserValidator.cs
Using Fluent Validation with WPF - Dead Simple
View UserValidator.cs
using System.Text.RegularExpressions;
using FluentValidation;
using WpfFluentValidationExample.ViewModels;
namespace WpfFluentValidationExample.Lib
{
public class UserValidator : AbstractValidator<UserViewModel>
{
public UserValidator()
{
@saga
saga / compile_stdlib.py
Created Jul 26, 2016 — forked from madebyjazz/compile_stdlib.py
Compile all Python scripts into single StdLib.dll .NET assembly
View compile_stdlib.py
# Script below is based on following post:
# IronPython: EXE compiled using pyc.py cannot import module "os" - Stack Overflow
# http://stackoverflow.com/questions/6195781/ironpython-exe-compiled-using-pyc-py-cannot-import-module-os
import sys
sys.path.append('d:/projects/SomeProject/Libs/IronPython')
sys.path.append('d:/projects/SomeProject/Libs/IronPython/Lib')
sys.path.append('d:/projects/SomeProject/Libs/IronPython/Tools/Scripts')
import clr
@saga
saga / useshapeways.py
Created Mar 25, 2016 — forked from sbaer/useshapeways.py
shapeways sample
View useshapeways.py
"""Sample script that accesses the shapeways API
http://www.shapeways.com/api
"""
import wsdlprovider
wsdl_url = "http://api.shapeways.com/v1/wsdl.php"
username = "username"
password = "password"
application_id = "rhinotest"
@saga
saga / index.js
Created Feb 26, 2016 — forked from maxogden/index.js
requirebin sketch
View index.js
var graph = require('ngraph.generators').noLinks(142);
graph.forEachNode(assignNiceColor);
var clickMe = document.createElement('h1')
clickMe.setAttribute('style', 'font-family: Helvetica, Arial; font-weight: 200; text-align: center; margin-top: 150px;')
clickMe.innerHTML = 'CLICK ME'
document.body.appendChild(clickMe)
var svg = require('ngraph.vivasvg')(graph);
svg.nodeTemplate("<circle r='5' fill='{{node.color}}'></circle>");