Skip to content

Instantly share code, notes, and snippets.

View dehypnosis's full-sized avatar
🎯
Focusing

Daniel Kim dehypnosis

🎯
Focusing
View GitHub Profile
fn receipt_token_extra_account_metas() -> Result<Vec<ExtraAccountMeta>> {
let extra_account_metas = vec![
// index 5, fund account
ExtraAccountMeta::new_with_seeds(
&[
Seed::Literal {
bytes: FundAccount::SEED.to_vec(),
},
Seed::AccountKey { index: 1 }, // receipt_token_mint
],
@dehypnosis
dehypnosis / fragmetric_nsol_pool.rs
Created January 24, 2025 01:42
NSOL pool account deserialization example
use anchor_lang::{AnchorDeserialize, Discriminator};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::pubkey;
use solana_client::nonblocking::rpc_client::RpcClient;
const ID: Pubkey = pubkey!("fragnAis7Bp6FTsMoa6YcH8UffhEw43Ph79qAiK3iF3");
const NSOL_POOL: Pubkey = pubkey!("AkbZvKxUAxMKz92FF7g5k2YLCJftg8SnYEPWdmZTt3mp");
const NSOL_POOL_DISCRIMINATOR: [u8; 8] = [7, 113, 233, 177, 153, 66, 175, 56];
#[derive(AnchorDeserialize, Clone, Debug)]
const getSizeOfObject = obj => {
const typeSizes = {
"undefined": () => 0,
"boolean": () => 4,
"number": () => 8,
"string": item => 2 * item.length,
"object": item => !item ? 0 : Object
.keys(item)
.reduce((total, key) => sizeOf(key) + sizeOf(item[key]) + total, 0)
};
@dehypnosis
dehypnosis / k8s-remove-old-telepresence-deployments.sh
Created August 23, 2019 09:17
kubernetes remove old telepresence deployments
#!/usr/bin/env bash
kubectl get deploy --all-namespaces \
-l telepresence \
-o custom-columns=namespace:.metadata.namespace,name:.metadata.name,age:.metadata.creationTimestamp \
| awk -v yesterday=`date -u -v -1d +%FT%TZ` \
'{if ($3 < yesterday) system("kubectl delete deploy --grace-period=0 -n " $1 " " $2) }'
@dehypnosis
dehypnosis / icloud-nosync.bashrc
Last active March 27, 2019 20:32
bash functions for icloud nosync, resync
# icloud sync management shell functions
# Simple usage
$ nosync ./node_modules
$ resync ./some_dir ./and_dir ./and/deep/file_or_whatever
# example to call with pipe:
$ find ./test -type file | xargs -I{} zsh -c 'source ~/.zshrc && nosync {}'
$ ls -al test
total 0
@dehypnosis
dehypnosis / replace_josa.go
Created November 24, 2018 10:57
golang 한국어 조사 치환
// 은/는, 을/를, 이/가, 과/와 조사 치환 (마지막 글자의 종성이 있는 경우 첫째 조사, 종성이 없는 경우 둘째 조사 채택)
var josas = map[string][]string{
"은/는": { "은", "는" },
"을/를": { "을", "를" },
"이/가": { "이", "가" },
"과/와": { "과", "와" },
"는/은": { "은", "는" },
"를/을": { "을", "를" },
"가/이": { "이", "가" },
"와/과": { "과", "와" },
@dehypnosis
dehypnosis / memorize.js
Last active January 15, 2021 18:37
js memorize function
// memorization for performance; don't use this for mutable function
function memorize(fun) {
const cache = {};
return function(){
const args = Array.prototype.slice.call(arguments);
const key = JSON.stringify(args);
// fetch
let hit = cache[key];
android {
buildToolsVersion "24.0.0"
compileSdkVersion 24
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
@dehypnosis
dehypnosis / restangular-extended.js
Last active September 8, 2015 15:42
Extended Restangular (it will be made as a independent module, soon )
angular
.module('app', ['restangular'])
/** ServerSide validation presenter **/
.factory('Validator', function(){
return {
clean: function($form) {
if (typeof $form == 'string') {
$form = angular.element('form[name="'+$form+'"]').controller('form');