Skip to content

Instantly share code, notes, and snippets.

@ericdke
ericdke / launch.json
Created December 31, 2020 18:16
VSCode multiple CPP files
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
@ericdke
ericdke / get_pnut_oembed.txt
Created July 30, 2017 14:04
Flow to get an image from a pnut.io post oembed
if the post oembed does NOT have a "url_expires_at" field:
it's not a pnut file, it's safe to use the "url" field from the post oembed
else:
if "url_expires_at" is NOT past:
it's safe to use "url" field from the post oembed
@ericdke
ericdke / emojiImage.swift
Created June 17, 2017 08:56
Swift 4 String extension for converting an emoji to an NSImage. Idea and original code by Daniel Jalkut http://indiestack.com/2017/06/evergreen-images/.
import Cocoa
extension String {
// https://stackoverflow.com/a/36258684/2227743
var containsEmoji: Bool {
for scalar in self.unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
@ericdke
ericdke / swift_loc.sh
Created October 21, 2016 13:55
Count LOCs in Swift/Xcode project, ignoring pods
# Thanks https://gist.github.com/Tokuriku/f7d6ce5a68d2154c28b0#gistcomment-1781457
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
if let imageSource = CGImageSourceCreateWithURL(fileURL as CFURL, nil) {
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)
if let dict = imageProperties as? [String: Any] {
print(dict)
}
}
@ericdke
ericdke / random_probability_generator.cpp
Last active October 6, 2020 04:15
C++: random number generator
#include <iostream>
#include <iomanip>
#include <random>
// this template comes from http://stackoverflow.com/a/39183450/2227743
template<class Ty = double, class = std::enable_if<std::is_floating_point<Ty>::value>>
class random_probability_generator {
public:
// default constructor uses single random_device for seeding
random_probability_generator()
@ericdke
ericdke / download.cpp
Last active September 24, 2023 06:42
C++: Download a file using HTTP GET and store in in a std::string
/**
* HTTPDownloader.hpp
*
* A simple C++ wrapper for the libcurl easy API.
*
* Written by Uli Köhler (techoverflow.net)
* Published under CC0 1.0 Universal (public domain)
*/
#ifndef HTTPDOWNLOADER_HPP
#define HTTPDOWNLOADER_HPP
@ericdke
ericdke / get_int.cpp
Last active August 16, 2016 17:41
C++: get int from console input
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int get_int()
{
string input;
int num;
getline(cin, input);
@ericdke
ericdke / urlcharsets.txt
Created May 10, 2016 08:16
URL encoding NSCharacterSet characters
URLQueryAllowedCharacterSet
!$&'()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~
URLHostAllowedCharacterSet
!$&'()*+,-.0123456789:;=ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz~
URLPathAllowedCharacterSet
@ericdke
ericdke / numericSearch.swift
Created March 12, 2016 17:28
Get strings containing non padded numbers sorted properly by numeric order
let names = ["h8", "h9", "h10", "h11", "h4", "h12", "h5", "h6"]
let result = names.sort { $0.compare($1, options: .NumericSearch) == .OrderedAscending }
result // ["h4", "h5", "h6", "h8", "h9", "h10", "h11", "h12"]