Skip to content

Instantly share code, notes, and snippets.

@sergiotapia
sergiotapia / images_dimensions.go
Last active February 13, 2024 17:40
Golang - Getting the dimensions of an image. jpg, jpeg, png
package main
import (
"fmt"
"image"
"os"
_ "image/jpeg"
_ "image/png"
)
# alias to edit commit messages without using rebase interactive
# example: git reword commithash message
reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"
# edit all commit messages
git rebase -i --root
# clone all your repos with gh cli tool
gh repo list --json name -q '.[].name' | xargs -n1 gh repo clone
@msbarry
msbarry / README.md
Last active September 13, 2023 18:34
Visvalingam vs. Douglas-Peucker

Two well-known algorithms for polyline simplification are the Douglas Peucker and Visvalingam algorithms.

The Douglas Peucker algorithm uses a recursive divide-and-conquer approach. It starts by drawing a straight line from the first point to the last point. Then it finds the intermediate point that is furthest away from the straight line and deems this the "most important" and splits the polyline into two halves at that point. This process is repeated on both halves until the distance of the intermediate point is below a certain threshold, after which all points on that sub-polyline are thrown away since they have a negligible impact on the overall shape.

The Visvalingam algorithm works from the inside-out. It starts by computing the area of the triangle formed by each consecutive three points along the polyline. Then the midpoint of the triangle with the least area is thrown out since those three points are the closest to colinear and the area of triangles on either side are recomputed. The process

@robinmonjo
robinmonjo / minibian-setup.md
Last active December 7, 2017 02:24
Install + configure minibian from Mac

Prepare SD card

  • Download MiniBian
  • extract MiniBian .img
  • insert SD Card
  • use disk utility to format the card with fat32
  • check from terminal (OSX) which disk the SD Card is using diskutil list
  • unount SD Card: diskutil unmountDisk /dev/diskX where X is what you found out last step
  • copy image to SD Card: sudo dd bs=1m if=<path to the .img file> of=/dev/rdiskX
  • wait until dd is finished
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@techslides
techslides / github-gist-api.js
Last active January 1, 2022 23:03
GitHub API to make Gists with Ajax
/*
Assuming jQuery Ajax instead of vanilla XHR
*/
//Get Github Authorization Token with proper scope, print to console
$.ajax({
url: 'https://api.github.com/authorizations',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("USERNAME:PASSWORD"));
@tyndyll
tyndyll / bashpipe.go
Last active July 14, 2023 17:39
Execute Piped Shell Commands in Go
package main
import (
"bytes"
"io"
"log"
"os"
"os/exec"
)
@gavinandresen
gavinandresen / surprise_51.md
Last active May 7, 2021 19:50
Preventing "surprise" 51% attacks

Preventing "surprise" 51% attacks

Disclaimer: these are half-baked thoughts. Until the #bitcoin-wizards crew has had a chance to think about this really hard I won't consider them fully baked.

The idea: can we take advantage of the fact that almost all nodes are well-connected to the p2p network almost all of the time to limit the ability of a 51% attacker to pull off a multi-confirmation double-spend?

Lets start with a well-connected node that has been seeing new blocks arrive approximately every ten minutes at difficulty D. Assume for now that the node can be confident that it is not being Sybil attacked and is on the actual, best blockchain.

@ChuckJHardy
ChuckJHardy / digital_ocean_setup.md
Last active October 27, 2023 17:51
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

@rmondello
rmondello / gist:b933231b1fcc83a7db0b
Last active April 5, 2024 07:10
Exporting (iCloud) Keychain and Safari credentials to a CSV file

Exporting (iCloud) Keychain and Safari credentials to a CSV file

Update (October 2021)

Exporting password + one-time code data from iCloud Keychain is now officially supported in macOS Monterey and Safari 15 (for Monterey, Big Sur, and Catalina). You can access it in the Password Manager’s “gear” icon (System Preferences > Passwords on Monterey, and Safari > Passwords everywhere else), or via the File > Export > Passwords... menu item). You shouldn't need to hack up your own exporter anymore.

Original, Obsolete Content (2014)

After my dad died, I wanted to be able to have access any of his online accounts going forward. My dad was a Safari user and used iCloud Keychain to sync his credentials across his devices. I don’t want to have to keep an OS X user account around just to access his accounts, so I wanted to export his credentials to a portable file.