Skip to content

Instantly share code, notes, and snippets.

View hlfcoding's full-sized avatar
🇺🇦

Peng Wang hlfcoding

🇺🇦
View GitHub Profile
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
@malko
malko / makeTemplate.js
Created March 21, 2017 11:03
dynamic es6 template string to template methods
//const tpl = makeTemplate('hello ${name}')
//const name = 'world';
//tpl({name});
const makeTemplate = (templateString) => {
return (templateData) => new Function(`{${Object.keys(templateData).join(',')}}`, 'return `' + templateString + '`')(templateData);
}
@nybblr
nybblr / 1-easy.js
Last active July 13, 2022 03:40
3 examples of using Async Generators and Async Iteration in JavaScript!
// Create a Promise that resolves after ms time
var timer = function(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
// Repeatedly generate a number starting
// from 0 after a random amount of time
var source = async function*() {
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
@hlfcoding
hlfcoding / !nationbuilder-ios-compact-example.md
Last active March 17, 2016 03:13
Compact Example Using NationBuilder iOS SDK
@hlfcoding
hlfcoding / !nationbuilder-ios-with-swift.md
Last active March 17, 2016 03:11
Using NationBuilder iOS SDK with Swift

Using NationBuilder iOS SDK with Swift

Additional Steps

  1. Put use_frameworks! in your Podfile. Use pod 'NBClient', '~> 1.3.0'. Re-run Cocoapods.
  2. Add bridging header to your project. See [guide].
  3. Refer to the same AppDelegate source to continue.

Caveats

@hlfcoding
hlfcoding / Learn CSS the Hard Way.md
Last active March 16, 2023 19:16
Learn CSS the Hard Way - Example-driven talk that focuses in-depth on CSS2 fundamentals and best practices for real-world scenarios. Examples are interactive. There are also resources (below) for further learning. Everything is online for future reference and experimentation: http://codepen.io/collection/XOLJBj

Introduction (5min)

  • (Setup: http://codepen.io/hlfcoding/pen/vEzpVd, stopwatch, printout of this, all pens loaded.)
  • Reason for this talk: better 'general knowledge of' (will be less lost) / 'fundamental knowledge how to' (will do it right).
  • Format of the talk. Provide general outline. Q&A time after each point.
  • History and personal history with CSS.
    • How complexity has been introduced in places and resolved in others.

Topics

@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
@sebmarkbage
sebmarkbage / ElementFactoriesAndJSX.md
Last active May 17, 2022 11:06
New React Element Factories and JSX

New React Element Factories and JSX

In React 0.12, we're making a core change to how React.createClass(...) and JSX works.

If you're using JSX in the typical way for all (and only) React components, then this transition will be seamless. Otherwise there are some minor breaking changes described below.

The Problem

@hlfcoding
hlfcoding / find_closest_prime.py
Last active August 29, 2015 14:02
Given a number, find its closest prime number.
from math import sqrt
def is_prime(n):
print 'Checking {}'.format(n)
if n == 1: return True
root = sqrt(n)
if root % 1 == 0:
print "{} isn't prime, with square root of {}".format(n, root)
return False
try_factor = 2