Skip to content

Instantly share code, notes, and snippets.

@pebble8888
pebble8888 / main.go
Created October 3, 2017 14:23
nareix/joy4/examples
package main
import (
"fmt"
"os"
"encoding/binary"
"math"
)
import (
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def desc(self):
from math import *
from fractions import Fraction
from sys import *
def twice(x, y):
x2 = (x*x*x*x-16*x)/(4*x*x*x+8)
y2 = sqrt_frac(x2*x2*x2+2)
return x2, y2
def sqrt_frac(x):
@pebble8888
pebble8888 / is_prime
Last active July 5, 2017 14:29
is_prime python
def isprime(n):
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
lsof |grep XXX|wc -l
@pebble8888
pebble8888 / .cpp
Created April 21, 2017 00:54
shared_ptr
#include <iostream>
#include <thread>
#include <memory>
#include <vector>
#include <atomic>
using namespace std;
struct T {
T(){
#include <stdio.h>
#include <assert.h>
int main(int argc, const char * argv[]) {
FILE* fp = fopen("/tmp/a.log", "w");
for (int i = 0; i < 512; ++i){
FILE* dummp_fp = fopen("/tmp/a.out", "r");
if (dummp_fp == nullptr){
char buf[256];
sprintf(buf, "i[%d]\n", i);
@pebble8888
pebble8888 / allocator sample.txt
Created March 11, 2017 14:44
C++ allocator sample
#include <cstdlib>
template <class T>
struct MyAllocator {
using value_type = T;
// default constractor
// copy constractor
// move constractor
MyAllocator()
if let stream:InputStream = InputStream(fileAtPath: "/Users/pebble8888/hoge.txt") {
var buf:[UInt8] = [UInt8](repeating: 0, count: 16)
stream.open()
while true {
let len = stream.read(&buf, maxLength: buf.count)
print("len \(len)")
for i in 0..<len {
print(String(format:"%02x ", buf[i]), terminator: "")
}
if len < buf.count {
@pebble8888
pebble8888 / gist:1884dd4357d608a74d276e7796286dd5
Last active February 16, 2017 07:39
swift jsonObject description
let a = try JSONSerialization.data(withJSONObject: ["alpha":["beta":"あいう", "gamma":"えおか"]], options: [])
let b = try JSONSerialization.jsonObject(with: a, options: [])
print("\(debugDescriptionUTF8(dic:b))")
let c = try JSONSerialization.data(withJSONObject: ["alpha":["さしす", "せそた"]], options: [])
let d = try JSONSerialization.jsonObject(with: c, options: [])
print("\(debugDescriptionUTF8(dic:d))")
func debugDescriptionUTF8(dic:Any) -> String {
guard let dic = dic as? [String:Any] else {