Skip to content

Instantly share code, notes, and snippets.

View ZPVIP's full-sized avatar

Peng Zhang ZPVIP

  • Boise, ID, USA
  • 19:18 (UTC -06:00)
View GitHub Profile

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
config = Rails.application.config
cookie = CGI::unescape(cookie)
salt = config.action_dispatch.authenticated_encrypted_cookie_salt
encrypted_cookie_cipher = config.action_dispatch.encrypted_cookie_cipher || 'aes-256-gcm'
# serializer = ActiveSupport::MessageEncryptor::NullSerializer # use this line if you don't know your serializer
serializer = ActionDispatch::Cookies::JsonSerializer
@ZPVIP
ZPVIP / udp_server.exs
Created March 26, 2022 11:26 — forked from joshnuss/udp_server.exs
Fault tolerant UDP Server in Elixir
# to run:
# > elixir --no-halt udp_server.exs
# to test:
# > echo "hello world" | nc -u -w0 localhost 2052
# > echo "quit" | nc -u -w0 localhost 2052
# Let's call our module "UDPServer"
defmodule UDPServer do
# Our module is going to use the DSL (Domain Specific Language) for Gen(eric) Servers
use GenServer
@ZPVIP
ZPVIP / zugriffsverletzung.md
Created October 25, 2021 09:51
Delphi zugriffsverletzung

zugriffsverletzung bei adresse in modul themeloader280.bpl

socket error 10022 on startup.

Run command line as administrator

Enter commands line by line

netsh WinSock reset
@ZPVIP
ZPVIP / i73770.cpp
Last active October 25, 2021 12:19
i73770
#include <cmath>
#include <iostream>
#include <limits>
void main()
{
// 1. use this result is always: 3.5677476354876406e-05
//_set_FMA3_enable(0);
// 2. use this result is always: 3.5677476354876413e-05
@ZPVIP
ZPVIP / 0dedict.py
Created July 21, 2020 13:09 — forked from josephg/0dedict.py
Apple dictionaries
# Thanks to commenters for providing the base of this much nicer implementation!
# Save and run with $ python 0dedict.py
# You may need to hunt down the dictionary files yourself and change the awful path string below.
# This works for me on MacOS 10.14 Mohave
from struct import unpack
from zlib import decompress
import re
filename = '/System/Library/Assets/com_apple_MobileAsset_DictionaryServices_dictionaryOSX/9f5862030e8f00af171924ebbc23ebfd6e91af78.asset/AssetData/Oxford Dictionary of English.dictionary/Contents/Resources/Body.data'
f = open(filename, 'rb')
@ZPVIP
ZPVIP / snowflake.go
Created July 3, 2020 20:54 — forked from asyncins/snowflake.go
[snowflake-go]
package main
import (
"errors"
"fmt"
"sync"
"time"
)
const (
@ZPVIP
ZPVIP / google_speech2text.md
Created February 2, 2020 13:55 — forked from alotaiba/google_speech2text.md
Google Speech To Text API

Google Speech To Text API

Base URL: https://www.google.com/speech-api/v1/recognize
It accepts POST requests with voice file encoded in FLAC format, and query parameters for control.

Query Parameters

client
The client's name you're connecting from. For spoofing purposes, let's use chromium

lang
Speech language, for example, ar-QA for Qatari Arabic, or en-US for U.S. English

@ZPVIP
ZPVIP / Todo.md
Last active September 27, 2019 19:26
Todo list for cooperation
# Extracted from the following library
# http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/
#--
# Utility for creating Google Maps Encoded GPolylines
# License: You may distribute this code under the same terms as Ruby itself
# Author: Joel Rosenberg
class DouglasPeucker
# The minimum distance from the line that a point must exceed to avoid
# elimination under the DP Algorithm.