Skip to content

Instantly share code, notes, and snippets.

View amankkg's full-sized avatar
👽
debloating random codebases

Aman Kubanychbek amankkg

👽
debloating random codebases
View GitHub Profile
var files = Directory.EnumerateFiles(".").OrderBy(x => x).ToArray();
for (int i = 0; i < files.Length / 2; i++)
{
var paper = i / 2 + 1;
var side = i % 2 == 0 ? 1 : 2;
var page1 = i;
var page2 = files.Length - i - 1;
File.Move(files[page1], $"{paper}-{side}-{(side == 1 ? 'a' : 'b')}-{page1 + 1}.jpg");
@amankkg
amankkg / get-unit-form.js
Last active October 22, 2019 13:41
Unit word form, word ending, unit suffix (for Russian)
// type getUnitForm = ([string, string, string]) => (number) => string
export const getUnitForm = ([nominative, genitive, plural]) => (num) => {
num = Math.abs(num) % 100
if (num >= 11 && num <= 19) return plural
switch (num % 10) {
case (1): return nominative
case (2):
case (3):
@amankkg
amankkg / fonts.conf
Created April 28, 2019 13:28
~/.config/fontconfig/fonts.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
@amankkg
amankkg / foo.js
Created April 14, 2019 13:22
lens usage
import R from 'ramda'
const recordsLens = R.lensPath(['foo', 'records'])
const keysLens = R.lensPath(['bar', 'keys'])
const reducer = (state, {type, payload}) => {
switch (type) {
case 'SET_RECORDS': return R.set(recordsLens, payload, state)
case 'SET_RECORD': {
const exactRecordLens = R.lensPath([payload.id])
@amankkg
amankkg / fib.hs
Created December 18, 2018 21:24
Fibonacci number: support negative values, recursive and optimized versions
fib :: Integer -> Integer
fib n
| n == 0 = 0
| abs n == 1 = 1
| n > 0 = fib (n - 2) + fib (n - 1)
| otherwise = fib (n + 2) - fib (n + 1)
fib2 :: Integer -> Integer
fib2 n = fib2' 0 1 2 n
@amankkg
amankkg / Form.jsx
Created July 6, 2018 21:52
simple form and controlled input
class Form extends React.Component {
state = { value: '' }
onChange = e => this.setState({ value: e.currentTarget.value })
onSubmit = () => console.log('The value is ', this.state.value)
render() {
return (
<form onSubmit={this.onSubmit}>
@amankkg
amankkg / UploadItem.cs
Created November 20, 2017 15:44
asp.net core, accept file and form
public class UploadItem
{
[Required, Range(1, int.MaxValue)]
public int DataSourceId { get; set; }
public string Description { get; set; }
}
const trickyPropType = getPropTypeFromProps =>
(props, propName, componentName) => {
const error = getPropTypeFromProps(props)(props, propName, componentName)
if (error) return error // WIP
}
const Summary = ({ hasErrors, errors }) =>
<div>
{hasErrors &&
errors.map(err => <span key={err}>{err}</span>)}
@amankkg
amankkg / sample.js
Last active August 4, 2017 16:13
no-complex-logic-in-prop-types.js
const withErrors = shape({ hasErrors: oneOf([true]).isRequired, errors: arrayOf(string).isRequired })
const withoutErrors = shape({ hasErrors: oneOf([false]).isRequired, errors: arrayOf(string) })
const result = oneOfType([withErrors, withoutErrors])
{
"scripts": {
"postinstall": "dotnet restore nscreg.Server nscreg.Server.Test",
"eslint": "eslint client client.test run.js webpack.config.js",
"stylelint": "stylelint \"client/components/**/*.pcss\" \"client/pages/**/*.pcss\"",
"lint": "run-p eslint stylelint",
"test": "",
"test:watch": "",
"clean": "node run clean",
"build": "node run build",