Skip to content

Instantly share code, notes, and snippets.

View chapmanjacobd's full-sized avatar
🥅
goal_net

Jacob Chapman chapmanjacobd

🥅
goal_net
View GitHub Profile
@karol-majewski
karol-majewski / flatMap.ts
Last active February 2, 2023 13:48
The simplest flatMap implementation in TypeScript
export function flatMap<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => U[]): U[] {
return Array.prototype.concat(...array.map(callbackfn));
}
// npm install twit
const Twit = require("twit");
// Fill this in
const T = new Twit({
consumer_key: "???",
consumer_secret: "???",
access_token: "???",
access_token_secret: "???"
});
@yancya
yancya / EXCEPT.sql
Created December 15, 2017 11:04
INTERSECT and EXCEPT for BigQuery
#standardsql
WITH a AS (
SELECT * FROM UNNEST([1,2,3,4]) AS n
), b AS (
SELECT * FROM UNNEST([4,5,6,7]) AS n)
SELECT * FROM a
@bbengfort
bbengfort / balance.py
Created December 7, 2017 02:11
Database transactions blog post.
#!/usr/bin/env python3
import os
import logging
import psycopg2 as pg
from decimal import Decimal
from functools import wraps
from psycopg2.pool import ThreadedConnectionPool
@valpackett
valpackett / global-input-unstable-v1.xml
Last active November 20, 2022 18:40
global-input wayland protocol DRAFT PREVIEW
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="global_input_v1">
<copyright>
Copyright (C) 2017 Val Packett ([email protected])
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@SpotlightKid
SpotlightKid / open-in-firefox.sh
Last active February 13, 2024 10:38
Open URL from Termux command line in Firefox Android browser
#!/bin/bash
#
# open-in-firefox.sh - open URL from Termux command line in Firefox Android browser
#
# Works with file:// URLs too, unlike with termux-open{-url}.
#
exec am start --user 0 -a android.intent.action.VIEW -n org.mozilla.firefox/.App -d "$1" >/dev/null
@manix
manix / sample.js
Last active March 1, 2024 23:51
Improved "fieldSorter"
function fieldSorterOptimized(fields) {
var dir = [], i, l = fields.length;
fields = fields.map(function(o, i) {
if (o[0] === "-") {
dir[i] = -1;
o = o.substring(1);
} else {
dir[i] = 1;
}
return o;
To create a new Device ID (and reset configuration) after cloning a VM with Syncthing, just remove the content of this folder:
- Unix-like: $HOME/.config/syncthing
- Mac: $HOME/Library/Application Support/Syncthing
- Windows XP: %AppData%/Syncthing
- Windows 7+: %LocalAppData%/Syncthing

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@vijayanandrp
vijayanandrp / Wikipedia Scraper using Scrapy.py
Last active March 16, 2024 14:55
Wikipedia Scraper using Scrapy
# -*- coding: utf-8 -*-
import scrapy
import re
import unicodedata
from scrapy.crawler import CrawlerProcess
from urllib.parse import urlparse
class WikiSpider(scrapy.Spider):
name = 'wiki_company'