Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
sachin-handiekar / OrganizationServiceUtil.java
Last active December 14, 2021 22:58
An utility class/managed bean(JSF) to manage user's roles and group assignment in exoplatform gatein container.
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.log4j.Logger;
import org.exoplatform.commons.utils.secure.SecureSet;
@yurydelendik
yurydelendik / gist:f2b846dae7cb29c86d23
Last active January 20, 2026 06:37
PDF.js get/show hightlight
function getHightlightCoords() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
var pageRect = page.canvas.getClientRects()[0];
var selectionRects = window.getSelection().getRangeAt(0).getClientRects();
var viewport = page.viewport;
var selected = selectionRects.map(function (r) {
return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat(
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
});
@heyalexej
heyalexej / gsm-setup.md
Last active August 20, 2025 21:09
SIM Card Management Through GSM Modem On Linux

SIM Card Management Over GSM Modem

A small guide on how to send and receive USSD codes on Linux

I am using the built in GSM (UMTS) modem of my Thinkpad X1 extensively because I am often in places with flaky internet connections. I connect through the standard Network Manager on Ubuntu and everything works fine. There was one major annoyance though. Every time I wanted to top up the SIM balance or book a new package, I needed a phone to send and receive USSD codes. So I took some time to figure out how to do it from the shell. I wrote this down as a help for others and a reminder for myself. Without further ado...

First intsall gammu and picocom.

~  sudo apt-get install -y gammu picocom
@fontanon
fontanon / app.js
Created February 20, 2015 17:45
NodeJS Passport-LDAPAuth Express test
var express = require('express'),
passport = require('passport'),
bodyParser = require('body-parser'),
LdapStrategy = require('passport-ldapauth');
// Credentials from the free LDAP test server by forumsys
// More info at: http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
var OPTS = {
server: {
url: 'ldap://ldap.forumsys.com:389',
@octavian-nita
octavian-nita / gitignore++.flt
Last active July 21, 2025 08:10
WinMerge directory/file filter to ignore .git and IDE-specific files and directories
## This is a directory/file filter for WinMerge
name: gitignore++
desc: Ignore .git and IDE-specific files and directories
## Select if filter is inclusive or exclusive
## Inclusive (loose) filter lets through all items not matching rules
## Exclusive filter lets through only items that match to rule
## include or exclude
def: include
@dannvix
dannvix / electron-main.js
Created June 24, 2015 15:44
Create Electron's BrowserWindow with dynamic HTML content
// main.js for Electron
var app = require("app"),
BrowserWindow = require("browser-window");
app.on("window-all-closed", function() {
app.quit();
})
var mainWindow = null;
app.on("ready", function() {
@dcollien
dcollien / ImageTools.es6
Last active July 17, 2026 19:09
Resize Images in the Browser
let hasBlobConstructor = typeof(Blob) !== 'undefined' && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}());
let hasArrayBufferViewSupport = hasBlobConstructor && typeof(Uint8Array) !== 'undefined' && (function () {
try {
@Grokzen
Grokzen / Symmetrical ManyToMany Filter Horizontal in Django Admin.py
Last active September 4, 2024 11:27
Symmetrical ManyToMany Filter Horizontal in Django Admin
# Based on post from: https://snipt.net/chrisdpratt/symmetrical-manytomany-filter-horizontal-in-django-admin/#L-26
# Only reposting to avoid loosing it.
"""
When adding a many-to-many (m2m) relationship in Django, you can use a nice filter-style multiple select widget to manage entries. However, Django only lets you edit the m2m relationship this way on the forward model. The only built-in method in Django to edit the reverse relationship in the admin is through an InlineModelAdmin.
Below is an example of how to create a filtered multiple select for the reverse relationship, so that editing entries is as easy as in the forward direction.
IMPORTANT: I have no idea for what exact versions of Django this will work for, is compatible with or was intended for.
@pschichtel
pschichtel / nginx_rtmp.conf
Created October 3, 2015 15:05
A nginx configuration adding an RTMP server for collection of multiple streams from the local network
rtmp {
server {
listen 0.0.0.0:1935;
chunk_size 4096;
# The collection server, streaming allowed from standard local /16 subnets
# Stream to rtmp://<server ip>/collect/<stream key>
@jestin
jestin / gist:118ea8fec7dfeed91767
Created November 21, 2015 05:05
Sample Arduino code that can be used to calibrate a servo
// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
// use serial monitor to test
#include <Servo.h>