Skip to content

Instantly share code, notes, and snippets.

@nanom1t
nanom1t / gist:cb086e21853926969da85726357f2e2f
Created May 1, 2017 18:42 — forked from klovadis/gist:5170446
Two Lua scripts for Redis to turn HGETALL and HMGET into dictionary tables
-- gets all fields from a hash as a dictionary
local hgetall = function (key)
local bulk = redis.call('HGETALL', key)
local result = {}
local nextkey
for i, v in ipairs(bulk) do
if i % 2 == 1 then
nextkey = v
else
result[nextkey] = v
CREATE OR REPLACE FUNCTION insta5.next_id(OUT result bigint) AS $$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
now_millis bigint;
shard_id int := 5;
BEGIN
SELECT nextval('insta5.table_id_seq') %% 1024 INTO seq_id;
SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000) INTO now_millis;
@nanom1t
nanom1t / ufw.md
Created January 4, 2018 09:26 — forked from kimus/ufw.md
NAT and FORWARD with Ubuntu’s ufw firewall

UFW

I use Ubuntu’s Uncomplicated firewall because it is available on Ubuntu and it's very simple.

Install UFW

if ufw is not installed by default be sure to install it first.

@nanom1t
nanom1t / install-comodo-ssl-cert-for-nginx.rst
Created April 3, 2018 19:02 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@nanom1t
nanom1t / nginx-tls.conf
Created April 3, 2018 19:04 — forked from gavinhungry/nginx-tls.conf
Nginx SSL/TLS configuration for "A+" Qualys SSL Labs rating
#
# Name: nginx-tls.conf
# Auth: Gavin Lloyd <gavinhungry@gmail.com>
# Desc: Nginx SSL/TLS configuration for "A+" Qualys SSL Labs rating
#
# Enables HTTP/2, PFS, HSTS and OCSP stapling. Configuration options not related
# to SSL/TLS are omitted here.
#
# Example: https://www.ssllabs.com/ssltest/analyze.html?d=gav.sh
#
@nanom1t
nanom1t / DateUtilsFormatDateTime.java
Created June 10, 2018 10:06 — forked from MizzleDK/DateUtilsFormatDateTime.java
Examples with DateUtils.formatDateTime()
long date = 1407869895000L; // August 12, 2014, 8:58PM
// August 12, 2014 (default)
DateUtils.formatDateTime(this, date, 0);
// Aug 12, 2014 (default with abbreviated month)
DateUtils.formatDateTime(this, date, DateUtils.FORMAT_ABBREV_MONTH);
// August 12 (date without year)
DateUtils.formatDateTime(this, date, DateUtils.FORMAT_NO_YEAR);
@nanom1t
nanom1t / ToggleImageButton
Created June 21, 2018 06:28 — forked from akshaydashrath/ToggleImageButton
A ToggleImageButton for Android
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.ImageButton;
public class ToggleImageButton extends ImageButton implements Checkable {
@nanom1t
nanom1t / AppHelper.java
Created July 18, 2018 18:37 — forked from anggadarkprince/AppHelper.java
Upload file with Multipart Request Volley Android
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.ByteArrayOutputStream;
/**
* Sketch Project Studio
* Created by Angga on 12/04/2016 14.27.
*/
public class AppHelper {
@nanom1t
nanom1t / gist:c8d2c1a77af974e4c3e42e4d69b1fff7
Created August 17, 2018 12:01 — forked from Neolot/gist:3964380
PHP Склонение числительных
<?php
/**
* Функция склонения числительных в русском языке
*
* @param int $number Число которое нужно просклонять
* @param array $titles Массив слов для склонения
* @return string
**/
$titles = array('котик', 'котика', 'котиков');
function declOfNum($number, $titles)
@nanom1t
nanom1t / verify.js
Created August 23, 2018 07:35 — forked from evanhalley/verify.js
Using JavaScript / Node.js to do server side IAB signature verification
var crypto = require('crypto');
// the Base64 encoded Google Play license key / Base64-encoded RSA public key from the Google Play Dev Console
var publicKey = "ABCEDF1234....";
/** sample
{
"orderId":"12999763169054705758.1371079406387615",
"packageName":"com.example.app",
"productId":"exampleSku",