Skip to content

Instantly share code, notes, and snippets.

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

zuozuo dcalsky

🏠
Working from home
  • The University of Hong Kong
  • Hong Kong
View GitHub Profile
@ecnelises
ecnelises / qregex.c
Last active January 13, 2016 10:00
支持基本正则运算的正则引擎
/*
* regex.c
* Qiu Chaofan, 2016/1/12
*
* Regular expression engine.
*
* Features:
* Support matching for | * ? + . ()
* No error handling is considered yet.
*/
@fred3m
fred3m / Multilayer Canvas
Created March 11, 2015 03:33
An html5 canvas with multiple layers
// Canvas with multiple layers
// copyright 2015 by Fred Moolekamp
// MIT License
initMultiCanvas=function(div,options){
var $div;
if(div instanceof jQuery){
$div=div;
}else{
$div=$(div);
};
@zhanwenchen
zhanwenchen / export_tf_model.py
Last active August 31, 2021 22:51
Minimal code to load a trained TensorFlow model from a checkpoint and export it with SavedModelBuilder
import os
import tensorflow as tf
trained_checkpoint_prefix = 'checkpoints/dev'
export_dir = os.path.join('models', '0') # IMPORTANT: each model folder must be named '0', '1', ... Otherwise it will fail!
loaded_graph = tf.Graph()
with tf.Session(graph=loaded_graph) as sess:
# Restore from checkpoint
loader = tf.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
@ubermajestix
ubermajestix / inspector.rb
Created September 5, 2012 20:35
Override inspect on ruby objects
# When an RSpec test like this fails,
#
# @my_array.should == [@some_model, @some_model2]
#
# RSpec will call inspect on each of the objects to "help" you figure out
# what went wrong. Well, inspect will usually dump a TON OF SHIT and make trying
# to figure out why `@my_array` is not made up of `@some_model` and `@some_model2`.
#
# This little module and technique helps get around that. It will redefine `inspect`
# if you include it in your model object.
@AlexV525
AlexV525 / create_images.dart
Last active November 17, 2023 10:28
How do we create images through RepaintBoundary or Widget? (Null safety version)
///
/// [Author] Alex (https://github.com/AlexV525)
/// [Date] 07/30/21 5:29 PM
///
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
@talltyler
talltyler / gist:5345894
Created April 9, 2013 14:01
This code gives the HTML canvas element JavaScript support for letter spacing. Don't confuse letter spacing with kerning http://en.wikipedia.org/wiki/Kerning This code is basically from http://stackoverflow.com/a/15509006
(function(){
var _fillText,
__slice = [].slice;
_fillText = CanvasRenderingContext2D.prototype.fillText;
CanvasRenderingContext2D.prototype.fillText = function() {
var args, offset, previousLetter, str, x, y,
_this = this;
# Video: http://rubyhoedown2008.confreaks.com/08-chris-wanstrath-keynote.html
Hi everyone, I'm Chris Wanstrath.
When Jeremy asked me to come talk, I said yes. Hell yes. Immediately. But
then I took a few moments and thought, Wait, why? Why me? What am I supposed
to say that's interesting? Something about Ruby, perhaps. Maybe the
future of it. The future of something, at least. That sounds
keynote-y.
@revotu
revotu / remove_attrs.py
Last active January 27, 2024 06:48
remove all HTML attributes with BeautifulSoup except some tags(<a> <img>...)
from bs4 import BeautifulSoup
# remove all attributes
def _remove_all_attrs(soup):
for tag in soup.find_all(True):
tag.attrs = {}
return soup
# remove all attributes except some tags
def _remove_all_attrs_except(soup):
package auth
import (
"context"
"net/http"
"strings"
"google.golang.org/grpc/metadata"
"github.com/andela/micro-api-gateway/pb/authorization"
@rogeriochaves
rogeriochaves / main.py
Created July 10, 2023 05:34
MULTI_PROMPT_ROUTER_TEMPLATE improved
"""You help triaging user requests. Given a raw text input, output either DOCS or DEFAULT, according to those definitions:
DOCS: if user is asking a seemingly technical question, programming questions or company-specific questions
DEFAULT: if user is just chit-chatting or basic knowledge questions
====================
Input: hello there
Output: DEFAULT