Skip to content

Instantly share code, notes, and snippets.

@islishude
islishude / install_llvm_clang.sh
Last active January 31, 2024 22:21
install LLVM and clang++ 6.0+ version on Ubuntu
# ref: https://apt.llvm.org/
# 8
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
# LLVM
apt-get install libllvm-8-ocaml-dev libllvm8 llvm-8 llvm-8-dev llvm-8-doc llvm-8-examples llvm-8-runtime
# Clang and co
apt-get install clang-8 clang-tools-8 clang-8-doc libclang-common-8-dev libclang-8-dev libclang1-8 clang-format-8 python-clang-8
@islishude
islishude / string_iterator.cpp
Created June 11, 2019 02:08
utf8 iterator for cpp
#include <codecvt>
#include <locale>
#include <iostream>
#include <string>
int main()
{
std::u32string input = U"这是中文";
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
@islishude
islishude / python_with_as_syntax.py
Last active August 27, 2019 11:51
python with...as 语法
class Sample:
def __init__(self):
pass
def __enter__(self):
return self
def __exit__(self, type, value, trace):
# 如果语句体的退出是由异常导致的,并且来自 __exit__() 方法的返回值为假,则该异常会被重新引发。
# 如果返回值为真,则该异常会被抑制,并会继续执行 with 语句之后的语句。
@islishude
islishude / sol_call.solidity
Last active August 31, 2019 00:11
differents with lower-level call and call with interface in Solidity
pragma solidity ^0.5.0;
// see https://solidity.readthedocs.io/en/v0.5.9/control-structures.html#error-handling-assert-require-revert-and-exceptions
// When exceptions happen in a sub-call, they “bubble up” (i.e. exceptions are rethrown) automatically.
// Exceptions to this rule are send and the low-level functions call, delegatecall and staticcall –
// those return false as their first return value in case of an exception instead of “bubbling up”.
contract Caller {
constructor() public {}
from abc import ABC, ABCMeta, abstractmethod
class Reader(ABC):
@abstractmethod
def read(self): ...
class Writer(metaclass=ABCMeta):
@abstractmethod
@islishude
islishude / mock_requests.py
Created August 5, 2019 08:55
python requests mock
import requests
import json
from httmock import HTTMock, response
def get_mock(*args, **kwarg):
content = json.dumps({"mock": "test"})
return response(status_code=200, content=content)
@islishude
islishude / gist:2e4258e245d418630bc1a901a1a392cf
Created August 13, 2019 08:30
update all matched item in array
> db.test.remove({})
WriteResult({ "nRemoved" : 3 })
> db.test.insert({data:[1,2,3,1]})
WriteResult({ "nInserted" : 1 })
> db.test.insert({data:[2,3,4,5]})
WriteResult({ "nInserted" : 1 })
> db.test.insert({data:[1,2,3,1]})
WriteResult({ "nInserted" : 1 })
> db.test.insert({data:[1,2,3,1]})
WriteResult({ "nInserted" : 1 })
@islishude
islishude / gorm_one2many.go
Created August 18, 2019 08:13
gorm-one2many-example
package main
import (
"fmt"
"log"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
@islishude
islishude / gorm_one2one.go
Created August 18, 2019 08:28
gorm_one2one_example
package main
import (
"fmt"
"log"
"time"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
package main
import (
"fmt"
"log"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)