Skip to content

Instantly share code, notes, and snippets.

View ConAlgorithm's full-sized avatar

Contribute ConAlgorithm

View GitHub Profile
@ConAlgorithm
ConAlgorithm / str2color.js
Created March 20, 2021 14:02 — forked from axetroy/str2color.js
根据一个字符串,生成一个动态的hex颜色
var stringToColor = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var color = '#';
for (var i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
color += ('00' + value.toString(16)).substr(-2);
}
@ConAlgorithm
ConAlgorithm / Device.java
Created May 5, 2019 15:14 — forked from hormesiel/Device.java
How to get an Android device's serial number, visible to the user in "Settings > About phone/tablet/device > Status > Serial number".
import android.os.Build;
import java.lang.reflect.Method;
public class Device {
/**
* @return The device's serial number, visible to the user in {@code Settings > About phone/tablet/device > Status
* > Serial number}, or {@code null} if the serial number couldn't be found
*/
public static String getSerialNumber() {
@ConAlgorithm
ConAlgorithm / jsonArrayToElasticsearch.js
Created January 21, 2019 20:19 — forked from stiekel/jsonArrayToElasticsearch.js
Import array in JSON file to Elasticsearch
// import json array file to elasticsearch
const fs = require('fs')
const shelljs = require('shelljs')
let endpoint = process.argv[2]
let jsonFile = process.argv[3]
if (!endpoint || !jsonFile || endpoint.search('_bulk') === -1) {
console.log('sample: node jsonArrayToES.js localhost:9200/bank/customer/_bulk customer.json')
process.exit()
}
@ConAlgorithm
ConAlgorithm / ini2json.py
Created December 21, 2018 14:00 — forked from Natim/ini2json.py
Convert an ini configuration file into a json file
# -*- coding: utf-8 -*-
import json
import sys
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
class StrictConfigParser(ConfigParser):
def _read(self, fp, fpname):