Skip to content

Instantly share code, notes, and snippets.

@fogmoon
fogmoon / rounding_decimals.md
Created June 6, 2019 16:28 — forked from jackiekazil/rounding_decimals.md
How do I round to 2 decimals in python?

How do I round to 2 decimals?

In python, you have floats and decimals that can be rounded. If you care about the accuracy of rounding, use decimal type. If you use floats, you will have issues with accuracy.

All the examples use demical types, except for the original value, which is automatically casted as a float.

To set the context of what we are working with, let's start with an original value.

Original Value

@fogmoon
fogmoon / scatter_example.js
Created February 22, 2019 08:45 — forked from miguelmota/scatter_example.js
JavaScript Scatter EOSIO (eosjs) example
const ScatterJS = require('scatterjs-core').default
const ScatterEOS = require('scatterjs-plugin-eosjs').default
const Eos = require('eosjs')
ScatterJS.plugins(new ScatterEOS())
const connectionOptions = {
initTimeout: 10000
}
const network = {
....
exports.genGameHash = function(serverSeed) {
return crypto.createHash('sha256').update(serverSeed).digest('hex');
};
function divisible(hash, mod) {
// We will read in 4 hex at a time, but the first chunk might be a bit smaller
// So ABCDEFGHIJ should be chunked like AB CDEF GHIJ
var val = 0;
@fogmoon
fogmoon / gist:e4c235e4bfc1be4b3a3ea9069ac33b32
Created October 9, 2018 13:26 — forked from stereokai/gist:36dc0095b9d24ce93b045e2ddc60d7a0
CSS rounded corners with gradient border
.rounded-corners-gradient-borders {
width: 300px;
height: 80px;
border: double 4px transparent;
border-radius: 80px;
background-image: linear-gradient(white, white), radial-gradient(circle at top left, #f00,#3020ff);
background-origin: border-box;
background-clip: content-box, border-box;
}
@fogmoon
fogmoon / parseURLParameters.js
Created September 11, 2018 06:35 — forked from pirate/parseURLParameters.js
Parse URL query parameters in ES6
function getUrlParams(search) {
let hashes = search.slice(search.indexOf('?') + 1).split('&')
let params = {}
hashes.map(hash => {
let [key, val] = hash.split('=')
params[key] = decodeURIComponent(val)
})
return params
}
@fogmoon
fogmoon / git-branch.md
Created May 28, 2018 02:39 — forked from yisibl/git-branch.md
在Mac、Linux 终端显示 Git 当前所在分支

在Mac、Linux 终端显示 Git 当前所在分支

  1. 进入你的home目录
cd ~
  1. 编辑.bashrc文件
@fogmoon
fogmoon / post-merge
Created March 15, 2018 12:37 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
public static class PostBuildTrigger
{
// Frameworks Ids - These ids have been generated by creating a project using Xcode then
// extracting the values from the generated project.pbxproj. The format of this
// file is not documented by Apple so the correct algorithm for generating these
@fogmoon
fogmoon / WWWClient.cs
Created October 12, 2017 16:45 — forked from cloned/WWWClient.cs
A handy class to use WWW and WWWForm on Unity.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace WWWKit
{
/// <summary>
/// A handy class to use WWW class and WWWForm class.
///
/// Features:
@fogmoon
fogmoon / PushBehaviorScript.cs
Created October 12, 2017 04:04 — forked from gfosco/PushBehaviorScript.cs
Parse Push for Unity iOS
using UnityEngine;
using System.Collections;
using Parse;
public class PushBehaviorScript : MonoBehaviour {
bool tokenSent = false;
public ParseObject currentInstallation = null;
void Start () {