Skip to content

Instantly share code, notes, and snippets.

View urjitbhatia's full-sized avatar

Urjit Singh Bhatia urjitbhatia

View GitHub Profile
@shiki
shiki / beanstalkd
Created August 9, 2010 13:41
For CentOS, a modified /etc/init.d/beanstlkd file which creates a pid file in /var/run/beanstalkd.pid
#!/bin/sh
#
# beanstalkd - a simple, fast workqueue service
#
# chkconfig: - 57 47
# description: a simple, fast workqueue service
# processname: beanstalkd
# config: /etc/sysconfig/beanstalkd
#
@lovasoa
lovasoa / piper.rs
Last active September 12, 2019 07:49
rust : convert a writer function to an io::Read
extern crate pipe;
/**
Some libraries (such as handlebars or serde) offer functions that can generate data when given
an object that implements io::Write.
Some other libraries (such as Rocket) can consume data only from objects implementing io::Read.
Here is an example `piper` function that can be used to make these two kinds of libraries together.
@uttampawar
uttampawar / gist:5407f998bc3f02f58c4b83b0b4dc20fe
Last active March 28, 2020 05:43
llvm-propeller optimization on the included test program.
Hardware information:
OS: 4.15.0-58-generic (uname -r)
VERSION="18.04.3 LTS (Bionic Beaver)"
GCC: gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
GNU ld (GNU Binutils for Ubuntu) 2.30
$ clang++ -O2 main.cc callee.cc -fpropeller-label -o a.out.labels -fuse-ld=lld
$ perf record -e cycles:u -j any,u -- ./a.out.labels 1000000000 2 >& /dev/null
$LLVM_DIR/llvm-propeller/create_llvm_prof --format=propeller --binary=./a.out.labels --profile=perf.data --out=perf.propeller
@adrianlzt
adrianlzt / gist:6864843
Created October 7, 2013 09:07
Netcat testing 3306 tcp connexion
[root@centos mysql]# nc -vz localhost 3306
nc: connect to localhost port 3306 (tcp) failed: Connection refused
Connection to localhost 3306 port [tcp/mysql] succeeded!
The reason is the first connection is against ::1 (IPv6), and the second to 127.0.0.1.
This could be seen with: tcpdump -i lo -n
[root@centos mysql]# grep localhost /etc/hosts
@torsten
torsten / expanding-json-arrays-to-rows.sql
Last active April 8, 2021 15:35
Expanding JSON arrays to rows with SQL on RedShift: All queries to reproduce the technique from my blog post https://torsten.io/stdout/expanding-json-arrays-to-rows
-- Related blog post to this Gist:
-- https://torsten.io/stdout/expanding-json-arrays-to-rows
-- Run these commands on a interactive RedShift session:
CREATE TEMP TABLE clusters AS (
SELECT 1 AS id, '[1, 2]' AS node_sizes UNION ALL
SELECT 2 AS id, '[5, 1, 3]' AS node_sizes UNION ALL
SELECT 3 AS id, '[2]' AS node_sizes
);
@koenbollen
koenbollen / idle_darwin.go
Created October 3, 2017 14:44
Golang example of detecting user activity (using CGEventSourceSecondsSinceLastEventType from CoreGraphics)
package main
// #cgo LDFLAGS: -framework CoreGraphics
// #include <CoreGraphics/CoreGraphics.h>
import "C"
import (
"fmt"
"math"
)
@burnash
burnash / get_oauth2_token.py
Last active August 11, 2021 21:16
Simple command line script to fetch a Google API's access token.
'''
This script will attempt to open your webbrowser,
perform OAuth 2 authentication and print your access token.
It depends on two libraries: oauth2client and gflags.
To install dependencies from PyPI:
$ pip install python-gflags oauth2client
@zz
zz / UbuntuCongestionControlBBR.md
Last active February 12, 2022 16:46 — forked from chalos/UbuntuCongestionControlBBR.md
Ubuntu using BBR
@jmoiron
jmoiron / valuer.go
Created October 14, 2013 18:03
Example uses of sql.Scanner and driver.Valuer
package main
import (
"bytes"
"compress/gzip"
"database/sql/driver"
"errors"
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
@kainam00
kainam00 / slowserver.py
Created November 4, 2016 18:36
A simple HTTP server designed to be slow. Useful for testing LB timeouts and such.
#!/usr/bin/env python
# Includes
import getopt
import sys
import os.path
import subprocess
import BaseHTTPServer
import SocketServer
import time