Skip to content

Instantly share code, notes, and snippets.

@peicheng
peicheng / id.go
Created May 9, 2018 16:43 — forked from jordanorelli/id.go
fast unique id generation in Go
package main
import (
"crypto/md5"
"encoding/binary"
"fmt"
"os"
"sync/atomic"
"time"
)
@peicheng
peicheng / instagram_shortcode.py
Created May 7, 2018 13:49
Instagram shortcode to media id media id to shortcode
# coding=utf-8
'''
Instagram shortcode to media id
media id to shortcode
'''
sid = 'BFBQEQDxVqV'
# 1243345632996186773
nid = ''
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
@peicheng
peicheng / InsertDate.gs
Created April 26, 2018 09:31 — forked from thomxc/InsertDate.gs
Google Docs Script Macro: Insert Date
/**
* The onOpen function runs automatically when the Google Docs document is
* opened. Use it to add custom menus to Google Docs that allow the user to run
* custom scripts. For more information, please consult the following two
* resources.
*
* Extending Google Docs developer guide:
* https://developers.google.com/apps-script/guides/docs
*
* Document service reference documentation:

steps:

  • you need to have node.js installed

  • copy main.js & package.json to a new folder

  • in the terminal:

    • to build it, run: npm install and then npm start

    • to pack it like a regular app, use 'electron-packager'. install it globally by running: npm install electron-packager -g

@peicheng
peicheng / gist:c1609ba521666d12f65abca9ffc71b00
Created June 5, 2017 05:57
Idonethis export todos bookmarklet
<a href='javascript:loc=location.href;
title=document.title;
x=document.getElementsByClassName("editable entry-body");
y=window.open();
y.document.write("<html><body><h3>Links: "+loc+"</h3>\n");
var todolist = document.getElementsByClassName("editable entry-body");
for(var i = 0; i < todolist.length; i++) {
var todo = todolist[i].innerText;
@peicheng
peicheng / generate-pushid.js
Created December 26, 2016 10:50 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
import random
import time
import numpy
from exceptions import ValueError
class PushID(object):
# Modeled after base64 web-safe chars, but ordered by ASCII.
PUSH_CHARS = ('-0123456789'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@peicheng
peicheng / gist:41afe17ec741d7749590
Created January 15, 2015 02:48
Bookmarklet:post to plurk
javascript: (function () {
title = '';
setitle = '';
if (window.getSelection) setitle = window.getSelection();
if (document.getSelection) setitle = document.getSelection();
if (document.selection) setitle = document.selection.createRange().text;
str = '';
str = title.toString();
if (str.length == 0) title = document.title;
// To create a clone of pad CWrp961Hnw as of revision 3:
// http://sketchpad.cc/sp/pad/newsketch?clonePadId=CWrp961Hnw&cloneRevNum=3
// --------------------------------------------------------------------------------
// in etherpad/src/etherpad/control/pad/pad_control.js
// --------------------------------------------------------------------------------
import("etherpad.collab.collab_server.buildHistoricalAuthorDataMapForPadHistory");
# Index
---------------------------------------------------------------------
curl -XPUT http://localhost:9200/pictures/ -d '
{
"settings": {
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "standard",