Skip to content

Instantly share code, notes, and snippets.

@kiwiyou
kiwiyou / main.rs
Created September 1, 2021 09:11
Rust Fast I/O
fn main() {
let buf = stdin();
let mut token = buf.split_ascii_whitespace();
use std::fmt::Write;
// buf.clear();
let mut buf = String::new();
writeln!(buf, "{}", token.next().unwrap()).unwrap();
print!("{}", buf);
}
@seldo
seldo / can-spam.md
Last active May 2, 2023 19:52
CAN-SPAM

Hi! I notice your email doesn't contain instructions on how to unsubscribe, which is illegal:

https://www.ftc.gov/tips-advice/business-center/guidance/can-spam-act-compliance-guide-business

Despite its name, the CAN-SPAM Act doesn’t apply just to bulk email. It covers all commercial messages, which the law defines as “any electronic mail message the primary purpose of which is the commercial advertisement or promotion of a commercial product or service,” including email that promotes content on commercial websites. The law makes no exception for business-to-business email. That means all email – for example, a message to former customers announcing a new product line – must comply with the law.

Each separate email in violation of the CAN-SPAM Act is subject to penalties of up to $46,517, so non-compliance can be costly. But following the law isn’t complicated. Here’s a rundown of CAN-SPAM’s main requirements:

  1. Don’t use false or misleading header information.
  2. Don’t use deceptive subject lines.
@chrispsn
chrispsn / eval_in_context.js
Last active October 21, 2019 21:11
IE11-compatible version of Brian Beck's eval-in-context
// https://twitter.com/ua6oxa/status/1170457046153650176
"use strict";
function evalInContext(env, code) {
const
s = JSON.stringify,
locals = Object.keys(env),
keys = locals.map(function(k){return s(k)}),
values = locals.map(function(k){return env[k]}),
body = s("return eval(" + code + ")")
@amelnychuck
amelnychuck / TabBarViewController
Created July 27, 2017 23:23
Example of why we need closures to replace the last instances of #selectors in Cocoa Touch
import UIKit
class TabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: Keyboard Commands
@andrey-skl
andrey-skl / AppDelegate.m
Created November 16, 2016 14:36
How to enable logging in production build of React Native app
...
#import "RCTLog.h"
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTSetLogThreshold(RCTLogLevelInfo);
...
@jondot
jondot / keybez.md
Created January 14, 2016 16:49
ios keyboard bezier
  onKeyboardWillHide(e) {
    Animated.timing(this.state.height, {
      toValue: this.listViewMaxHeight,
      duration: e.duration,
      easing: Easing.bezier(0.1, 0.76, 0.55, 0.9)
    }).start();
  },

 onKeyboardWillShow(e) {
@wjordan
wjordan / dockerize.sh
Last active June 22, 2020 15:47
Dockerize: A tiny replacement for Dockerfiles
#!/bin/sh
####
# Dockerize: A tiny replacement for Dockerfiles
# This script leverages `docker run` and `docker commit` to provide a usable workaround for
# restrictions of `docker build` and Dockerfile syntax to strictly host-independent builds.
#
# See these discussions:
# https://github.com/docker/docker/pull/1124
# https://github.com/docker/docker/issues/3156
# https://github.com/docker/docker/issues/3949
@jokester
jokester / PixelExtractor.swift
Last active January 4, 2022 07:27
extract pixel from a CGImage
// extract pixel from a CGImage
/* use case:
let extractor = PixelExtractor(img: UIImage(named: "gauge_vertical")!.CGImage!)
let color = extractor.color_at(x: 10, y: 20)
*/
class PixelExtractor {
// taken from http://stackoverflow.com/questions/24049313/
// and adapted to swift 1.2
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class